Chapter 17 Categorical variables
nominal variables: represent data that are unordered
colors <- c("green", "blue", "yellow")
factor(colors)## [1] green blue yellow
## Levels: blue green yellow
Ordinal variables: ordered, ranked data
If you dont specify, R will do alphatecially
speed <- c("low", "high", "med", "med")
factor(speed, ordered = TRUE)## [1] low high med med
## Levels: high < low < med
If you specify:
speed <- c("low", "high", "med", "med")
factor(speed,
levels = c("low", "med", "high"),
ordered = TRUE)## [1] low high med med
## Levels: low < med < high
Grab a component from a list
mylist = list(A = c("a, b, d"),
cinema = ("stars"),
size = c(1, 2, 3, 4, 4))Three ways to select a column
mylist[[2]]## [1] "stars"
mylist[["cinema"]]## [1] "stars"
mylist$cinema## [1] "stars"