Introduction to R and RStudio


  • Use RStudio to write and run R programs.
  • R has the usual arithmetic operators.
  • Use <- to assign values to variables.
  • Use install.packages() to install packages (libraries).

Project Management With RStudio


  • Use RStudio to create and manage projects with consistent layout.
  • Treat raw data as read-only.
  • Treat generated output as disposable.

Data Structures


  • Use read.csv to read tabular data in R.
  • The basic data types in R are numeric, integer, complex, logical, character, and factor.
  • Dataframes store columns of the same data type as vectors.
  • Use characters and factors to represent categories in R.

Subsetting Data


  • Indexing in R starts at 1, not 0.
  • Access individual values by location using [].
  • Access slices of data using [low:high].
  • Access arbitrary sets of data using [c(...)].
  • Use logical operations and logical vectors to access subsets of data.

Data frame Manipulation with dplyr


  • Use the dplyr package to manipulate dataframes.
  • Use select() to choose variables from a dataframe.
  • Use filter() to choose data based on values.
  • Use group_by() and summarize() to work with subsets of data.
  • Use count() and n() to obtain the number of observations in columns.
  • Use mutate() to create new variables.

Introduction to Visualization


  • Use ggplot2 to create plots.
  • Think about graphics in layers: aesthetics, geometry, etc.

Writing Data


  • Save plots using ggsave() or pdf() combined with dev.off().
  • Use write.csv to save tabular data.