Contents

1 First Impressions

Type values and mathematical formulas into R’s command prompt

1 + 1
## [1] 2

Assign values to symbols (variables)

x = 1
x + x
## [1] 2

Invoke functions such as c(), which takes any number of values and returns a single vector

x = c(1, 2, 3)
x
## [1] 1 2 3

R functions, such as sqrt(), often operate efficienty on vectors

y = sqrt(x)
y
## [1] 1.000000 1.414214 1.732051

There are often several ways to accomplish a task in R

x = c(1, 2, 3)
x
## [1] 1 2 3
x <- c(4, 5, 6)
x
## [1] 4 5 6
x <- 7:9
x
## [1] 7 8 9
10:12 -> x
x
## [1] 10 11 12

Sometimes R does ‘surprising’ things that can be fun to figure out

x <- c(1, 2, 3) -> y
x
## [1] 1 2 3
y
## [1] 1 2 3

2 R Data types: vector and list

‘Atomic’ vectors

Lists

Factors

3 Classes: data.frame and beyond

Variables are often related to one another in a highly structured way, e.g., two ‘columns’ of data in a spreadsheet

x = rnorm(1000)       # 1000 random normal deviates
y = x + rnorm(1000)   # another 1000 deviates, as a function of x
plot(y ~ x)           # relationship bewteen x and y

Convenient to manipulate them together

A scatterplot makes one want to fit a linear model (do a regression analysis)

4 Help!

Help available in Rstudio or interactively