Multiple unions

后端 未结 5 826
南笙
南笙 2021-01-04 08:00

I am trying to do unions on several lists (these are actually GRanges objects not integer lists but the priciple is the same), basically one big union.

x<         


        
5条回答
  •  臣服心动
    2021-01-04 08:48

    I think it would be cleaner to separate the "dereference" part from the n-ary union part, e.g.

    dereflist <- function(l) lapply(a,get)
    nunion <- function(l) Reduce(union,l)
    

    But if you look at how union works, you'll see that you could also do

    nunion <- function(l) unique(do.call(c,l))
    

    which is faster in all the cases I've tested (much faster for long lists).

    -s

提交回复
热议问题