Before we Start


  • Use RStudio to write and run R programs.
  • Use install.packages() to install packages (libraries).

Introduction to R


  • Use the assignment operator <- to assign values to objects. You can now manipulate that object in R
  • R contains a number of functions you use to do something with your data. Functions automate more complicated sets of commands. Many functions are predefined, or can be made available by importing R packages
  • A vector is a sequence of elements of the same type. All data in a vector must be of the same type–character, numeric (or double), integer, and logical. Create vectors with c(). Use \[ \] to subset values from vectors.

Starting with Data


  • Use read.csv to read tabular data in R.
  • Use factors to represent categorical data in R.

Data cleaning & transformation 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 mutate() to create new variables.

Data Visualisation with ggplot2


  • ggplot2 is a flexible and useful tool for creating plots in R.
  • The data set and coordinate system can be defined using the ggplot function.
  • Additional layers, including geoms, are added using the + operator.
  • Boxplots are useful for visualizing the distribution of a continuous variable.
  • Barplot are useful for visualizing categorical data.
  • Faceting allows you to generate multiple plots based on a categorical variable.