Remove NULL elements from list of lists

后端 未结 7 2023
天涯浪人
天涯浪人 2020-11-27 20:20

How do I remove the null elements from a list of lists, like below, in R:

lll <- list(list(NULL),list(1),list(\"a\"))

The object I want

7条回答
  •  孤独总比滥情好
    2020-11-27 20:33

    Here's an option using Filter and Negate combination

    Filter(Negate(function(x) is.null(unlist(x))), lll)
    # [[1]]
    # [[1]][[1]]
    # [1] 1
    #
    #
    # [[2]]
    # [[2]][[1]]
    # [1] "a"
    

提交回复
热议问题