[R] How to union the elements in a list?

Ben Bolker bolker at ufl.edu
Wed Oct 28 20:27:09 CET 2009




Peng Yu wrote:
> 
> Suppose that I have a list of vectors. I want to compute the union of
> all the vectors in the list. I could use 'for' loop to do so. But I'm
> wondering what would be a better solution that does not need a 'for'
> loop.
> 
> l=list(a=c(1,3,4), b=c(1,3,6), c=c(1,3,7), ....)
> 
> 

Reduce(union,l)

-- 
View this message in context: http://www.nabble.com/How-to-union-the-elements-in-a-list--tp26100375p26100684.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list