Non exclusive outersection in R

To create a non exclusive outersection from the vectors in a list it is as easy as to perform an intersection of the vectors in the list and get the vector’s elements that are not in the intersection:

From post [Intersection in R] we recover the way to perform an intersection to a list of vectors:

intersect.list <- function(list.vec) {
    return(Reduce(intersect, list.vec))
}

And now we develop the function to create a non exclusive outersection:

outersect.list.nx <- function(list.vec) {
    common <- intersect.list(list.vec)
    big.vec <- unlist(list.vec)
    nonex <- big.vec[!(big.vec %in% common)]
    return(unique(nonex))
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: