For this lab, you will use R Markdown and knitr
to recreate this report exactly, including this paragraph. Specifically, use the mtcars
dataset in R to recreate the English text, table, and figure you see here in an html file like this one. Note: All the results printed in the “Introduction” section should be created using in-line R code. Remember to:
The R dataset mtcars
has 11 variables and 32 observations. The average fuel consumption reported was 20.09 mpg with a standard deviation of 6.03. The average horsepower was 146.69 (sd=68.56).
In this report, we create:
# Make transmission a factor variable
mtcars$am <- factor(mtcars$am, levels = c(0,1), labels = c("automatic",
"manual"))
# Group data by transmission
gcars <- group_by(mtcars, am)
# Get means for each variable
t1 <- summarise_each(gcars, funs(mean(., na.rm = T)), mpg, disp : qsec)
# Print knitr table
kable(t1, digits = 2,
caption = "Means of Fuel Consumption and Auto Design Elements")
am | mpg | disp | hp | drat | wt | qsec |
---|---|---|---|---|---|---|
automatic | 17.15 | 290.38 | 160.26 | 3.29 | 3.77 | 18.18 |
manual | 24.39 | 143.53 | 126.85 | 4.05 | 2.41 | 17.36 |