Skip to content

MJousse/IntroToR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Intro To R

Overview

This workshop is delivered in 6 modules and aims to get the user comfortable with basic R. It goes through installing R and Rstudio, learning about operators and data structures, functions, packages, and basics of data manipulation, including with dplyr, tidyr and visualisation with ggplot2.

Requirements

No knowledge requirements. To go through with the workshop, R version 4.0+ and Rstudio must be installed. Installation of R, RStudio and necessary packages are helped with in the slides and scripts. Please review the following topics if you're not comfortable with them:

  • basic linear algebra (operations with vectors and metrices)
  • mathematical operations (exponentials, logarithms)
  • basic statistics (mean, variance, median, standard deviation)
  • logical statements (AND, OR, NOT)

Sofware

Workshop Structure

Slides can be found here.

1. R basics

In the first module of the workshop, the goals are to familiarize with the language and the logic behind it; Get started with R studio and create your first project; Create your first .R file to write down the live code; and get comfortabble with installing packages.

Module content:

  • Seeking help
  • Installing packages

Script

2. Data types: attributes and built-in functions

In this section participants will understand the differences between classes, objects and data types in R; Compute arithmetic operations; Use logical operators; create objects of different types, learn about their attributes and apply some built-in functions in R; Subset and index objects; and get comfortable with vectorized operations.

Module content:

  • Vectors
  • Lists
  • Factors
  • Data frames
  • Arrays
  • Coercion

Script

3. Control structures

In this module, participants learn to use if-else, while, and for loops; as well as building their own functions; and what packages are.

Module Content

  • If..Else
  • While loop
  • For loop
  • Functions
  • Packages

Script

4. Basic data manipulation

In this module participants will learn how to read/write data to/from files with different formats (.tsv, .csv); become familiar with basic data-frame operations; (3) index and subset data frames using base R; manipulate individual data frame columns.

Module content:

  • Reading/writing data
  • Exploring data frames

Script

5. Advanced data manipulation

The fourth module participants will familiarize with the dplyr syntax; create pipes with the operator %>%; perform operations on data frames using dplyr and tidyr functions; learn how to join columns and rows of different data frames; and implement functions from external packages by reading their documentation in R.

Module content:

  • Handling data frames with dplyr
  • Other useful packages
  • Hands-on: advanced data manipulation

Script

6. Generating visual outputs

This section will show participants how to (1) Create basic plots using base R functions; (2) Understand how to connect data frames with ggplot2; (3) create basic graphs with ggplot2; (4) use factors to customize graphics in ggplot2; (5) use RMarkdown to generate customized reports.

Module content:

  • Figures with base R
  • Graphics with ggplot2

Script

Repo structure

├── README.md
├── .gitignore
├── _config.yaml
├── IntroToR.Rproj
├── Exercises
│   └── README.md
│   ├── data
│   │   └── co2_pcap_cons.csv
│   │   └── penguins.csv
│   ├── scripts
│   │   └── 01GettingStarted.Rmd and .html
│   │   └── 02DataTypes.Rmd and .html
│   │   └── 03ControlStructuresAndFunctions.Rmd and .html
│   │   └── 04BasicDataManipulation.Rmd and .html
│   │   └── 05AdvancedDataManipulation.Rmd and .html
│   │   └── 06GeneratingOutputs.Rmd and .html
├── Slides
│   └── IntroToR_CBHWorkshop.pptx
└── Outline
    └── workshopoutline.pdf #using the template provided

References

The materials for this workshop were based on the following sources:

Data in this workshop comes from:

Workshop created as part of the McGill Initiative in Computational Medicine

About

CBH Intro to R workshop

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages