I'm using the following to cumulatively (i.e., first pick first 2 elements and each time add 1 more; see output below) pick elements from vector mods
below. I wonder if there is a faster or simpler approach to doing this in BASE R?
n <- names(mtcars) # BASE R dataset
lapply(seq_along(n)[-1], function(i)n[seq_len(i)]) # any faster or simpler approach here?
[[1]]
[1] "mpg""cyl"
[[2]]
[1] "mpg""cyl""disp"
[[3]]
[1] "mpg""cyl""disp""hp"
[[4]]
[1] "mpg""cyl""disp""hp""drat"