Created
January 11, 2017 06:23
-
-
Save mGalarnyk/2cda5835749f45eb29896d3f723882c6 to your computer and use it in GitHub Desktop.
R Programming from John Hopkins Coursera Week 3 for the blog post https://medium.com/@GalarnykMichael/in-progress-review-course-2-r-programming-jhu-coursera-ad27086d8438#.oh2mghbu1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(datasets) | |
library(data.table) | |
iris_dt <- as.data.table(iris) | |
# 1 There will be an object called 'iris' in your workspace. | |
# In this dataset, what is the mean of 'Sepal.Length' for the species virginica? Please round your answer to the nearest whole number. | |
# Basic data.table syntax below . | |
#iris_dt[ essentially SQL Where class, select statement, groupby] | |
iris_dt[Species == "virginica",round(mean(Sepal.Length)) ] | |
# 3 | |
# what is the absolute difference between the average horsepower of | |
# 4-cylinder cars and the average horsepower of 8-cylinder cars? (interest whole number) | |
mtcars_dt <- as.data.table(mtcars) | |
mtcars_dt <- mtcars_dt[, .(mean_cols = mean(hp)), by = cyl] | |
round(abs(mtcars_dt[cyl == 4, mean_cols] - mtcars_dt[cyl == 8, mean_cols])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment