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.
Bu egzersiz
Foundations of Functional Programming with purrr
kursunun bir parçasıdırEgzersiz talimatları
- Load the
repurrrsivepackage. - Load the
wesandersondataset. - Examine the structure of the first element in
wesanderson. - Examine the structure of the
GrandBudapestelement inwesanderson.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# 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(___$___)