Chapter 4 The Basics

4.1 R can be our calculator

Addition (use +).

> 2+2
[1] 4

Multiplication (use *).

> 2*6
[1] 12

Division (use /).

> 150/3
[1] 50

…anything is possible

> ((2+3)*8)/123
[1] 0.3252033

💡 Type in your numbers either within the workshop.R file (TOP-RIGHT) or within the console (BOTTOM-RIGHT). Then to run - click Run at the top of the .R script or type ctrl/cmd + enter. The answer prints in the console.

4.2 R can be our notebook

We can save important information for later.

We can use <- or =

> my_name <- "Caitlin"
> paste("My name is", my_name)
[1] "My name is Caitlin"
> several_names <- c("Caitlin", "Dionne", "Lauren")
> paste("My name is", several_names)
[1] "My name is Caitlin" "My name is Dionne"  "My name is Lauren" 
> a_number <- 137
> another_number <- 120
> 
> a_number * another_number
[1] 16440
> a_number / another_number
[1] 1.141667
> (2*a_number) + another_number
[1] 394

💡 Students are encouraged to make their own variable names and get used to R coding symbols