R How do I extract first row of each matrix within a list?

前端 未结 2 705
一整个雨季
一整个雨季 2020-12-15 01:35

Say I have a list called mylist_1 with 2 matrices:

mylist_1

$region_1           
users   50  20  30
revenue 10000   3500    4000

$red            
users   2         


        
相关标签:
2条回答
  • 2020-12-15 02:13

    Or,

    lapply(mylist_1, `[`,1,)
    lapply(mylist_1, `[`,2,)
    
    0 讨论(0)
  • 2020-12-15 02:26

    To extract the first row per matrix you can use:

    lapply(mylist1, head, 1)
    

    Or, if you want to rbind them:

    do.call(rbind, lapply(lst, head, 1))
    

    Or for (only) the second row per matrix:

    lapply(lst, function(x) x[2,])
    
    0 讨论(0)
提交回复
热议问题