Lecture 2: Getting Started with R
Note
This is not a course in R!
RStudio Interface
Common object types in R:
Using Arrow (<-
):
Embodies the idea of assigned to
<-
for assignment=
has specific role in function evaluation=
is quicker to type and familiar from other languagesTwo solutions:
package::function()
Tip
Better to restart R session than use rm(list = ls())
R has several basic data structures:
Dimension | Homogeneous | Heterogeneous |
---|---|---|
1 | Vector | List |
2 | Matrix | Data Frame |
3+ | Array | nested Lists |
Vectors are containers for objects of identical type:
Two-dimensional arrays with same data type:
[,1] [,2] [,3]
[1,] 2 6 10
[2,] 6 10 14
[3,] 10 14 18
[,1] [,2] [,3]
[1,] 1 8 21
[2,] 8 25 48
[3,] 21 48 81
[,1] [,2] [,3]
[1,] 66 78 90
[2,] 78 93 108
[3,] 90 108 126
[1] 4
[1] 1 4 7
[1] 1 2 3
Lists can contain elements of different types:
Note
You only need to install a package once, but you need to load it each session
Data frames are table-like structures:
c()
, :
, seq()
, rep()
)