XOR or intersect for several vectors
2
0
Entering edit mode
Wendy Qiao ▴ 360
@wendy-qiao-4501
Last seen 9.7 years ago
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 [[alternative HTML version deleted]]
• 675 views
ADD COMMENT
0
Entering edit mode
@carlos-j-gil-bellosta-1569
Last seen 9.7 years ago
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
ADD COMMENT
0
Entering edit mode
@herve-pages-1542
Last seen 5 hours ago
Seattle, WA, United States
Hi Wendy, What about first generating a logical matrix describing the appartenance of each of your genes to each of your groups: > allgenes <- unique(c(A, B, C)) > m <- cbind(A=allgenes %in% A, B=allgenes %in% B, C=allgenes %in% C) > rownames(m) <- allgenes > m A B C a TRUE TRUE TRUE b TRUE FALSE FALSE c TRUE FALSE FALSE e FALSE TRUE FALSE f FALSE TRUE FALSE g FALSE FALSE TRUE l FALSE FALSE TRUE Then it's easy to query this matrix in any way you like. For example, to get the genes that belong to A and C: > m[ , "A"] & m[ , "C"] a b c e f g l TRUE FALSE FALSE FALSE FALSE FALSE FALSE The genes that belong to A or C: > m[ , "A"] | m[ , "C"] a b c e f g l TRUE TRUE TRUE FALSE FALSE TRUE TRUE The number of groups that each gene belongs to: > rowSums(m) a b c e f g l 3 1 1 1 1 1 1 The genes that belong to all the groups: > rowSums(m) == ncol(m) a b c e f g l TRUE FALSE FALSE FALSE FALSE FALSE FALSE etc... H. On 03/29/2011 08:02 PM, Wendy Qiao wrote: > 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 > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- Hervé Pagès Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M2-B876 P.O. Box 19024 Seattle, WA 98109-1024 E-mail: hpages at fhcrc.org Phone: (206) 667-5791 Fax: (206) 667-1319
ADD COMMENT

Login before adding your answer.

Traffic: 858 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6