Lists¶
AList <- list(1:5,
letters[1:6],
c(TRUE,FALSE,FALSE,TRUE))
AList
[[1]]
[1] 1 2 3 4 5
[[2]]
[1] "a" "b" "c" "d" "e" "f"
[[3]]
[1] TRUE FALSE FALSE TRUE
AList[1:2]
[[1]]
[1] 1 2 3 4 5
[[2]]
[1] "a" "b" "c" "d" "e" "f"
AList[1]
[[1]]
[1] 1 2 3 4 5
AList[[2]]
[1] "a" "b" "c" "d" "e" "f"
AList[[1:2]]
[1] 2
AList[[1:3]]
Error in AList[[1:3]]:
recursive indexing failed at level 2
Traceback:
length(AList)
[1] 3
FDR <- list(c("John","Delano"),
c("Roosevelt"))
names(FDR) <- c("first.name","last.name")
FDR
$first.name
[1] "John" "Delano"
$last.name
[1] "Roosevelt"
FDR <- list(first.name=c("John","Delano"),
last.name=c("Roosevelt"))
FDR
$first.name
[1] "John" "Delano"
$last.name
[1] "Roosevelt"
FDR$last.name
[1] "Roosevelt"
FDR[["last.name"]]
[1] "Roosevelt"
UK <- list(
country.name = c("England","Northern Ireland","Scotland",
"Wales"),
population = c(54786300,1851600,5373000,3099100),
area.sq.km = c(130279,13562,77933,20735),
GVA.cap = c(26159,18584,23685,18002))
UK
$country.name
[1] "England" "Northern Ireland" "Scotland" "Wales"
$population
[1] 54786300 1851600 5373000 3099100
$area.sq.km
[1] 130279 13562 77933 20735
$GVA.cap
[1] 26159 18584 23685 18002
data.frame(UK)
country.name population area.sq.km GVA.cap
1 England 54786300 130279 26159
2 Northern Ireland 1851600 13562 18584
3 Scotland 5373000 77933 23685
4 Wales 3099100 20735 18002
- R file: lists.R
- Rmarkdown file: lists.Rmd
- Jupyter notebook file: lists.ipynb
- Interactive version of the Jupyter notebook (shuts down after 60s):
- Interactive version of the Jupyter notebook (sign in required):