List structure
Often when working in R, you'll use data frames or vectors. Another kind of R object is a list. While lists can be complicated, lists are also incredibly powerful. Lists are like Hermione Granger's bag of holding (from Harry Potter); they can hold a wide variety of things. The contents of a list don't have to be the same data type, and as long as you know how it's organized, you can grab out what you need by subsetting.
Both named and unnamed lists can be subset using double square brackets [[ ]]
list this: listname[[ index ]]
If a list is named, you can also use $
for subsetting. The syntax list$elementname
pulls out the named element from the list. Like any other kind of object in R, you can use the str()
to determine the structure of the list.
Este ejercicio forma parte del curso
Foundations of Functional Programming with purrr
Instrucciones del ejercicio
- Load the
repurrrsive
package. - Load the
wesanderson
dataset. - Examine the structure of the first element in
wesanderson
. - Examine the structure of the
GrandBudapest
element inwesanderson
.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Load repurrrsive package, to get access to the wesanderson dataset
library(___)
# Load wesanderson dataset
data(___)
# Get structure of first element in wesanderson
str(___)
# Get structure of GrandBudapest element in wesanderson
str(___$___)