transpose nested list

后端 未结 5 1739
误落风尘
误落风尘 2021-01-19 03:27

I have a list structure which represents a table being handed to me like this

> l = list(list(1, 4), list(2, 5), list(3, 6))
> str(l)
List of 3
 $ :Lis         


        
5条回答
  •  隐瞒了意图╮
    2021-01-19 04:06

    Here is one idea with unlisting each list i.e.

    split(do.call(cbind, lapply(l, unlist)), seq(unique(lengths(l))))
    

    which gives,

    $`1`
    [1] 1 2 3
    
    $`2`
    [1] 4 5 6
    

提交回复
热议问题