Press "Enter" to skip to content

Subsetting Lists In R

Dave Mason continues his look at lists in R:

Subsetting the list with single brackets [] for the first element returns “Atlantic”. But if we take a closer look using the str() function, we see R returned the data as a class of type list:

> #Appears to return "Atlantic" as a character class.
> division[1]
$Name
[1] "Atlantic"
> #str shows us the return is actually a list of 1 element.
> str(division[1])
List of 1 $ Name: chr "Atlantic"

Dave also explains the difference between single brackets and double brackets for list elements.