[BioC] XOR or intersect for several vectors

Carlos J. Gil Bellosta cgb at datanalytics.com
Wed Mar 30 05:13:42 CEST 2011


2011/3/30 Wendy Qiao <wendy2.qiao at gmail.com>:
> Hi all,
>
> I am trying to get a list of genes that can distinguish 24 cell types. After
> comparing each cell type to the grand mean, I got a list of genes for each
> cell type. I want to check the intersect of all the lists and the unique
> genes for each cell type. I thought to use logical operators, such as XOR
> and intersect, but I found that all these operators are for two vectors
> only. Does anybody know if there is operator functions for several vectors.
>
> To explain my problem more clearly, here is an example...
>
> A = c("a","b","c")
> B = c("e","f","a")
> C = c("a","g","l")
>
> I want the outputs to be
>
> intersect_output = c("a")
> xor_output = c("b","c","e","f","g","l")
>
> Thank you in advance,
> Wendy

You can use Reduce() to vectorize intersection():

Reduce( intersect, list(A,B,C) )
[1] "a"

For the XOR part, you can do:

a <- c(A,B,C)
a <- table( a )
names( a[ a ==1 ] )
[1] "b" "c" "e" "f" "g" "l"

Best regards,

Carlos J. Gil Bellosta
http://www.datanalytics.com



More information about the Bioconductor mailing list