Section 8 List

8.1 Function

Example vector:

x <- c(1:20); y <- rep(c('R1','R2','R3'), each=4); z <- rep(c(T,F), length=4)

Function Explanation Example
list Create a list y <- list(Age=x, Region=y, Epi=z)
as.list Coerce into a list as.list(y)
is.list Check if its argument is a list is.list(y)
length Length of a list length(y)
attributes Attributes of a list attributes(y)


List


8.2 Example

?list

x <- c(1:20)
y <- rep(c('R1','R2','R3'), each=4)
z <- rep(c(T,F), length=4)

y <- list(Age=x, Region=y, Epi=z)
y

is.list(y)
names(y)

attributes(y)
str(y)


# Create an empty list
z <- vector('list', length=3)
names(z) <- c('Here','There','Everywhere')
z

Note: Data frames are special type of list with every element of the list of equal length.