Preliminaries

Include the following R code chunk at the beginning of your R Markdown documents so that all of the commands associated with our textbook are available to use.

library(fastR2)

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. I recommend that you generate an HTML file when you Knit. Once the preview of the HTML file opens, click on “Open in Browswer” so that you can access printing functionality.

Note that when you click the Knit button, R only looks within your R Markdown document for data and commands; anything that you’ve done at the console is not available. In particular, this means that you must include commands to import data sets within the R Markdown file.

If you need help

If you go to the Help menu and then select “R Markdown Quick Reference”, you will find a list of common formats you can create in an R Markdown document. In particular, note that you can include LaTeX commands like \(\frac{1}{2}\) within an R Markdown document.

Try this out

  1. Import the ClassSurveyResults.csv data file, and copy the code to do so within an R chunk below.
library(fastR2)
classSurvey=read.csv("C:/Users/M/Downloads/ClassSurveyResults.csv", header=T, na.strings="?")
  1. Create a histogram that displays the relationship between whether you play a sport and how many hours you spend working each week.
histogram(~classSurvey$Work | classSurvey$Sport)

  1. Write a sentence that summarizes what the histogram you created shows you. Make sure that you do this outside of the R code chunk so that the text appears normally.
    More people who do not play a sport work and they work more hours a week.