Remove empty elements from list with character(0)

后端 未结 5 1871
渐次进展
渐次进展 2020-12-13 08:33

How can I remove empty elements from a list that contain zero length pairlist as character(0), integer(0) etc...

list2
# $`hsa:7476         


        
5条回答
  •  我在风中等你
    2020-12-13 08:54

    For the sake of completeness, the purrr package from the popular tidyverse has some useful functions for working with lists - compact (introduction) does the trick, too, and works fine with magrittr's %>% pipes:

    l <- list(1:3, "foo", character(0), integer(0))
    library(purrr)
    compact(l)
    # [[1]]
    # [1] 1 2 3
    #
    # [[2]]
    # [1] "foo"
    

    or

    list(1:3, "foo", character(0), integer(0)) %>% compact
    

提交回复
热议问题