Prevent unlist to drop NULL values

前端 未结 4 679
梦毁少年i
梦毁少年i 2020-12-04 16:19

I have a vector of lists and I use unlist on them. Some of the elements in the vectors are NULL and unlist seems to be dropping them.<

4条回答
  •  时光说笑
    2020-12-04 17:12

    In this case (one level depth list) this should works too:

    a[sapply(a, is.null)] <- NA
    unlist(a)
    # p1 p2 p1 p2 p1 p2 p1 p2 
    #  2  5  3  4 NA NA  4  5
    

提交回复
热议问题