list of lists with different lengths to data.frame in R

前端 未结 2 1955
悲哀的现实
悲哀的现实 2021-01-12 10:47

I have read many answers in SO about converting list of lists to df. But, I have noticed that they all have the length of lists (within the main big list) to be the same. I

2条回答
  •  盖世英雄少女心
    2021-01-12 11:21

    Here's one way:

    R> as.data.frame(as.matrix(h1))
                                V1
    USA             10, 13, 17, 11
    RUSSIA                    NULL
    BRAZIL                    NULL
    CHINA        11, 11, 10, 8, 12
    TAIWAN 12, 9, 9, 11, 9, 12, 14
    CHILE                     NULL
    
    R> as.data.frame(as.matrix(h1))['TAIWAN', ]
    $TAIWAN
    [1] 12  9  9 11  9 12 14
    

提交回复
热议问题