Get a column from the list of information frames R

I am a beginner R and I am stuck in this problem. I had a data block, and using the split () function, I created a list of data frames, for example:

dfList <- split(mtcars, mtcars$cyl) 

Now I want to get a column of a specific data frame, for example. column 2 from data frame 1, so something like

 dfList[1][2] 

Now I can create for loops to get inside the data structure. But I can not find oneliner to do this if it exists. How can i do this? Thanks in advance!

+7
list split r dataframe
source share
1 answer

I put a docendo comment here to close the question.

If you want to extract an item from a list (and treat it as data.frame), rather than a subset of the list (to create a smaller list), you need to use the syntax [[ ]] . In addition, to get a column by index from data.frame, you need to either use [[ idx ]] or [, idx ] . These are pretty simple indexing operations that you probably want to see if you program in R. So your β€œright” call is probably

 dfList[[1]][[2]] 
+7
source share

All Articles