NewUsr_stat
NewUsr_stat

Reputation: 2571

Subset and combine elements of a list

I have a list of data.frames that looks like this:

...................................    
   $ 97 :'data.frame':  3 obs. of  2 variables:    
     ..$ row: int [1:3] 97 97 97     
     ..$ col: chr [1:3] "0" "0" "0"    
   $ 98 :'data.frame':  3 obs. of  2 variables:     
     ..$ row: int [1:3] 98 98 98      
     ..$ col: chr [1:3] "0" "0" "0"      
   $ 99 :'data.frame':  3 obs. of  2 variables:    
  ..$ row: int [1:3] 99 99 99
  ..$ col: chr [1:3] "0" "0" "0"

I would like to subset only $ col rows and combine that in this way:

............   
97: 0,0,0     
98: 0,0,0     
99: 0,1,0     

Thank you in advance

Upvotes: 0

Views: 41

Answers (1)

Wietze314
Wietze314

Reputation: 6020

use

do.call(rbind, lapply(lst,function(x) x$col))

Upvotes: 1

Related Questions