Tuesday, June 05, 2012

intersect for multiple vectors in R

Say you have

a <- c(1,3,5,7,9)
b <- c(3,6,8,9,10)
c <- c(2,3,4,5,7,9)

A straightforward way to do the job is:
More cleverly, and more conveniently if you have a lot of arguments:
Reduce(intersect, list(a,b,c))

The Reduce function is part of funprog {base}, which includes

Reduce(f, x, init, right = FALSE, accumulate = FALSE)
Filter(f, x)
Find(f, x, right = FALSE, nomatch = NULL)
Map(f, ...)
Position(f, x, right = FALSE, nomatch = NA_integer_)

I will learn it and put notes here later.

1 comment:

  1. The great service in this blog and the nice technology is visible in this blog. I am really very happy for the nice approach is visible in this blog and thank you very much for using the nice technology in this blog

    R Programming Online Training|
    Data Science Online Training|
    Hadoop Online Training