The list in R may contain elements of the different class (just like a data frame)
Collection of object which must have the same class of objects are:
data.tables and data.frames are internally lists with all its columns of equal length and with a class attribute.
myList = list(object,object,...)
> v = list("Nico has",40,"year")
> v
[[1]]
[1] "Nico has"
[[2]]
[1] 40
[[3]]
[1] "year"
dimnames = list(c("Row1", "Row2"), c("Col1", "Col2", "Col3"))
> dimnames
[[1]]
[1] "Row1" "Row2"
[[2]]
[1] "Col1" "Col2" "Col3"
names: Functions to get or set the variable name of a value.
l = list(name = "Nico", age = 40)
l
$name
[1] "Nico"
$age
[1] 40
> names(l)
[1] "name" "age"
l$name
[1] "Nico"
Example using the subset operators
> l = list(name = c("Nico","Mad","Mel"), age = c(40,7,4), colour=c("Red","Blue","Parse"))
> l
$name
[1] "Nico" "Mad" "Mel"
$age
[1] 40 7 4
$colour
[1] "Red" "Blue" "Parse"
> l[1]
$name
[1] "Nico" "Mad" "Mel"
> l["name"]
$name
[1] "Nico" "Mad" "Mel"
> name <- "name"
> l[name]
$name
[1] "Nico" "Mad" "Mel"
> l[[1]]
[1] "Nico" "Mad" "Mel"
> l$name
[1] "Nico" "Mad" "Mel"
# of
> l[["name"]]
[1] "Nico" "Mad" "Mel"
> name <- "name"
> l[[name]]
[1] "Nico" "Mad" "Mel"
> l[c(1,3)]
$name
[1] "Nico" "Mad" "Mel"
$colour
[1] "Red" "Blue" "Parse"
l[[c(1,3)]]
[1] "Mel"
# of
> l[[1]][[3]]
[1] "Mel"
> l[["n"]]
NULL
> l[["n", exact=FALSE]]
[1] "Nico" "Mad" "Mel"
lapply apply a function over an list.
> class(v)
[1] "list"
> l = list("Nico has",40,"year")
> length(l)
[1] 3
Data Structure
> l = list("Nico has",40,"year")
> str(v)
List of 3
$ : chr "Nico has"
$ : num 40
$ : chr "year"