Transpose a List of Lists

后端 未结 5 2023
我寻月下人不归
我寻月下人不归 2020-12-01 23:32

I have a list which contains list entries, and I need to transpose the structure. The original structure is rectangular, but the names in the sub-lists do not match.

5条回答
  •  感动是毒
    2020-12-02 00:26

    The purrr package now makes this process really easy:

    library(purrr)
    
    before %>% transpose()
    
    ## $x
    ## $x$a
    ##   a x
    ## 1 1 2
    ## 
    ## $x$b
    ##   b w
    ## 1 5 6
    ## 
    ## 
    ## $y
    ## $y$a
    ##   a y
    ## 1 3 4
    ## 
    ## $y$b
    ##   b z
    ## 1 7 8
    

提交回复
热议问题