Subsetting Lists In R

Kevin Feasel

2018-09-12

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.

Related Posts

Donating To The R Foundation

Mark Niemann-Ross explains how you can donate to the R Foundation: I benefit from the work of the R Foundation. They oversee the language, but also encourage a healthy ecosystem. CRAN happens because of them. Updates to R happen because of them. useR! happens because of them. Every day, you and I are the recipients […]

Read More

Timing Means Of Groups With R

John Mount shares some performance measures pitting data.table against various dplyr methods for calculating grouped means: In this reproduction attempt we see:– The dplyr time being around 0.05 seconds. This is about 5 times slower than claimed.– The dplyr sum()/n() time is about 0.2 seconds, about 5 times faster than claimed.– The data.table time being around 0.004 seconds. This is about three times as […]

Read More

Categories

September 2018
MTWTFSS
« Aug Oct »
 12
3456789
10111213141516
17181920212223
24252627282930