Skip to the content.

Introduction to R

Learning Objectives

  1. R syntax: Understand the different ‘parts of speech’.
  2. Data types structures in R: Describe the various data types and data structures.
  3. Data inspection and wrangling: Demonstrate the utilization of functions and indices to inspect and subset data from various data structures.
  4. Visualizing data: Demonstrate the use of the ggplot2 package to create plots for easy data visualization.

Installations

Download the most recent versions of R and RStudio:

Lessons

Part 1

  1. Introduction to R and RStudio
  2. R Syntax and Data Structure
  3. Functions and Arguments
  4. Reading in and inspecting data
Practice exercises I Answer key I

Part II

  1. Data Wrangling: Subsetting Vectors and Factors
  2. Packages and libraries
  3. Data wrangling: data frames, matrices and lists
  4. The %in% operator
  5. Reordering and matching
  6. Setting up a data frame to plot (+ the map() function)
Practice exercises II Answer key II

Part III

  1. Plotting with the ggplot2 package
  2. Using custom functions for consistent plots
  3. Generating a boxplot with ggplot2
  4. Writing to file and exporting plots
  5. Finding help
  6. Tidyverse
Practice exercises III Answer key III
Practice exercises IV Answer key IV


Building on the basic R knowledge

Resources

Cheatsheets


These materials have been developed by members of the teaching team at the Harvard Chan Bioinformatics Core (HBC). These are open access materials distributed under the terms of the Creative Commons Attribution license (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.