I am an R beginner and I am stuck on this problem. I had a dataframe and by using the split() function I have created a list of dataframes, e.g:
dfList <- split(mtcars, mtcars$cyl)
Now I want to retrieve a column of a specific dataframe, e.g. column 2 from dataframe 1, so something like
dfList[1][2]
What I can do right now is create for
loops to get inside the data structure. But I can't find a oneliner to do it, if it exists. How can I do that?
lapply(dfList, '[[', 2)
. If you need it as a matrixsapply(dfList, '[[',2)
– OvoiddfList[[1]][2]
? Here's an example for you to test:lst <- split(mtcats, mtcars$cyl)
and thenlst[[1]][2]
. – Hollylapply(dfList, '[[', 2)
wowza R syntax really is the worst – Stereo