Remove NULL elements from list of lists

后端 未结 7 2006
天涯浪人
天涯浪人 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:44

    Using purrr

    purrr::map(lll, ~ purrr::compact(.)) %>% purrr::keep(~length(.) != 0)
    [[1]]
    [[1]][[1]]
    [1] 1
    
    [[1]][[2]]
    [1] 2
    
    [[1]][[3]]
    [1] 3
    
    
    [[2]]
    [[2]][[1]]
    [1] "a"
    
    [[2]][[2]]
    [1] "b"
    
    [[2]][[3]]
    [1] "c"
    
    0 讨论(0)
提交回复
热议问题