In this lab you can use the interactive console to explore or Knit the document. Remember anything you type here can be “sent” to the console with Cmd-Enter (OS-X) or Ctrl-Enter (Windows/Linux) in an R code chunk.

Part 1

  1. Read in the Youth Tobacco study from http://johnmuschelli.com/intro_to_r/data/Youth_Tobacco_Survey_YTS_Data.csv and name it youth
library(readr)
youth = read_csv("http://johnmuschelli.com/intro_to_r/data/Youth_Tobacco_Survey_YTS_Data.csv")
## Parsed with column specification:
## cols(
##   .default = col_character(),
##   YEAR = col_double(),
##   Data_Value = col_double(),
##   Data_Value_Std_Err = col_double(),
##   Low_Confidence_Limit = col_double(),
##   High_Confidence_Limit = col_double(),
##   Sample_Size = col_double(),
##   DisplayOrder = col_double()
## )
## See spec(...) for full column specifications.
  1. Check youth for any problems.
problems(youth)
## [1] row      col      expected actual  
## <0 rows> (or 0-length row.names)
stop_for_problems(youth)

Part 2

  1. Load the readxl package with the library command. If it is not installed, install it via: RStudio –> Tools –> Install Packages
library(readxl)

Download in the dataset of monuments from: http://johnmuschelli.com/intro_to_r/data/Monuments.xlsx file to Monuments.xlsx

download.file("http://johnmuschelli.com/intro_to_r/data/Monuments.xlsx",
              destfile = "Monuments.xlsx",
              overwrite = TRUE)
  1. Use the read_excel() function in the readxl package to read the Monuments.xlsx file and call the output mon.
mon = read_excel("Monuments.xlsx")

Part 3

  1. Write out the mon object as a CSV file calling it “monuments.csv”, using readr::write_csv:
write_csv(mon, "monuments.csv")

Part 4

  1. Write out the mon object as a RDS file calling it “monuments.rds”, using readr::write_rds:
readr::write_rds(mon, "monuments.rds")