I have a nested list of named data frames, for example:
mylist2 <- list(
list(df1.a = data.frame(replicate(2,sample(0:1,5,rep=TRUE))), df2.b = data.frame(replicate(2,sample(0:1,5,rep=TRUE)))),
list(df3.c = data.frame(replicate(2,sample(0:1,5,rep=TRUE))), df4.d = data.frame(replicate(2,sample(0:1,5,rep=TRUE)))),
list(df5.e = data.frame(replicate(2,sample(0:1,5,rep=TRUE))), df6.f = data.frame(replicate(2,sample(0:1,5,rep=TRUE)))))
I run a test (it doesn't matter which test), and it creates a character vector telling me which data frames in this list are important:
test
[1] "df1.a" "df5.e"
What is the most efficient way to extract these data frames from a nested list using this character vector? The test shows only the names of the second list, so it nestedlist[test]does not work.
source
share