Indexing list data.frames - how to get all x-th columns?

I have a list of data.frames, and I am wondering if there is an easy indexing method to get all third columns of all data.frames. Or all columns named x? Speaking R:

lapply(names(mylist),function(x) mylist[[x]][,3]) 

Is there a way to do this by simply indexing, for example mylist [[]] [, 3]? (which does not work explicitly)

EDIT: And how do you do it when you want to use a function like nlevels in it, for example

  lapply(names(mylist),function(x) nlevels(mylist[[x]][,3])) 

given that column 3 is a factor.

+7
source share
1 answer

Perhaps this is somewhat simpler:

 lapply(mylist, "[[", 3) lapply(mylist, "[[", name_of_column) 
+10
source

All Articles