I have this nested data frame
test <- structure(list(id = c(13, 27), seq = structure(list(
`1` = c("1997", "1997", "1997", "2007"),
`2` = c("2007", "2007", "2007", "2007", "2007", "2007", "2007")),
.Names = c("1", "2"))), .Names = c("penr",
"seq"), row.names = c("1", "2"), class = "data.frame")
I want a list of all values in the second column, namely
result <- c("1997", "1997", "1997", "2007", "2007", "2007", "2007", "2007", "2007", "2007", "2007")
Is there an easy way to achieve this?
This line does the trick:
or equivalent:
or even:
The output of these functions is:
To get rid of the names above the character vector, call
as.character
on the resulting object:This is not an answer but a follow up/supplement to Paul's answer:
Consistently on any number of iterations the c method performs the best. However as I increased the number of iterations to 100000 unlist went from the poorest to very close to the c method.
1000 iterations
100,000 iterations
Again thanks for sharing Paul!
Benchmarking performed using
rbenchmark
on a win 7 machine running R 2.14.1