Announcements

In-Class

  • Slides: Tidy data, data manipulation verbs, and piping %>%.
  • In-class exercise:
    • Code: Lec01.R

For the rest of the class, please download any Code or Data files listed above from GitHub as follows:

  • Click on the GitHub link above
  • Navigate to the corresponding lecture folder
  • Click on the relevant file
  • Click on the “Raw” button
  • In your browser, go to File -> Save As… and save the file without .txt in the file name

Then please change the default application to open .R files to RStudio. You only need to do this once (unfortunately I don’t know how to do this on Windows):

  • Navigate to Lec01.R in a Finder window
  • Right click the file and select Open With -> Get Info
  • Under Open with: select RStudio and click Change All…

After-Class Updates

Connor pointed out an error with lines 134-136 in the original Lec01.R file. The command add_rownames() has been deprecated i.e. dropped. Replace these lines with the following, which uses the function rownames_to_column() from the tibble package:

mtcars <- mtcars %>% 
  tibble::rownames_to_column() %>% 
  rename("make_model"=rowname)

The :: in tibble:: serves two functions:

  • Sometimes two packages can have the same function name, like filter() exists in multiple packages. The :: disambiguates which package.
  • You can use a function from a package without loading the package itself using library(). So the above code block is identical in function to:
library(tibble)

mtcars <- mtcars %>% 
  rownames_to_column() %>% 
  rename("make_model"=rowname)