knitr::opts_chunk$set(echo = TRUE)
library(learnr)
tutorial_options(exercise.timelimit = 10, exercise.blanks = "___+")

Welcome!

Why learn to code as a cancer researcher?

Imagined learning curve

Our view of the learning curve

Course goals

Why R specifically

::: {style="font-size: 80%; text-align: left;"}

Upsides

Downsides?

:::

Quick demo

[LIVE DEMO]

Strategy of the course

Course format

Other helpful R resources

Acknowledgements

R Basics

The R console

Where the action happens!


R as calculator

List of key math operations

Logical operations

2^2 == 3

Objects in R

Creating variables

x <- 3 * 4
x

Variable types in R {.smaller}

Numbers

x <- 1
x <- 1.592E-39

Strings (text)

x <- 'abc'
x <- "abc"

Logical (true/false)

x <- TRUE
x <- FALSE
x <- T

Factors (categorical variables)

Variable naming

Not allowed: 4th, my var, weird?, etc. etc.

avgClicks

calculate_avg_clicks

NOT: var1 or a

Commonly used R data structures

Vectors {.smaller}

Making vectors

Use 'combine' function c()

num_vec <- c(1, 2, 3, 4)

log_vec <- c(TRUE, TRUE, FALSE, F)

str_vec <- c('this', 'is', 'a', 'vector', 'of', 'strings')

print(num_vec)

Shorthand to create a sequence of integers

1:4

Missing values

c(1, 2, NA)
c('a', 'b', NA)

Adding more data on to vectors {.smaller}

c() can also be used to add new elements to a vector

string_vec <- c("TP53", "PLEC", "DSPP", "PIK3CA")
string_vec2 <- c(string_vec, "BRAF")
string_vec2

Combining two vectors

string_vec <- c("TP53", "PLEC", "DSPP", "PIK3CA")
string_vec2 <- c("BRAF", "EGFR", "DUSP4")
c(string_vec, string_vec2)

Lists

Lists are basically like relaxed vectors, where elements don't have to be the same type

z <- list('a', 1, TRUE)
z

You can combine lists with the c() function as with vectors

z <- list('a', 1, TRUE)
c(z, 'c')

Matrix

Dataframe

Key concepts recap



AshirBorah/cp_bootcamp_r_tutorials documentation built on May 16, 2024, 3:24 p.m.