x=c(5, 8, 28, 29, 30) y=c(5, 8, 28, 29, 31) How can we compare these two vectors, whether each element is exactly matched with the elements in the other vector ? How can we get the non matched elements from both the vectors? Can anyone help? ________________________________ Notice: The information contained in this electronic mail message is intended only for the use of the designated recipient. This message is privileged and confidential. and the property of GVK BIO or its affiliates and subsidiaries. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone +91-40-66929999<tel:%2B91-40-66929999> and destroy any and all copies of this message in your possession (whether hard copies or electronically stored copies). [[alternative HTML version deleted]]
Either == or %in% if you care about order or not. Michael On Aug 8, 2012, at 7:00 AM, Sri krishna Devarayalu Balanagu <balanagudevarayulu at gvkbio.com> wrote:> x=c(5, 8, 28, 29, 30) > y=c(5, 8, 28, 29, 31) > How can we compare these two vectors, whether each element is exactly matched with the elements in the other vector ? > How can we get the non matched elements from both the vectors? > Can anyone help? > ________________________________ > Notice: The information contained in this electronic mail message is intended only for the use of the designated recipient. This message is privileged and confidential. and the property of GVK BIO or its affiliates and subsidiaries. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone +91-40-66929999<tel:%2B91-40-66929999> and destroy any and all copies of this message in your possession (whether hard copies or electronically stored copies). > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
> x=c(5, 8, 28, 29, 30) > y=c(5, 8, 28, 29, 31) > x==y[1] TRUE TRUE TRUE TRUE FALSE> which(x==y)[1] 1 2 3 4> which(x!=y)[1] 5> x[x!=y][1] 30> y[x!=y][1] 31 RTFM! - just kidding ;) also, this might not work for floating point numbers, theres a section in the documentation/faq somewhere about it. On 08.08.2012, at 14:00, Sri krishna Devarayalu Balanagu wrote:> x=c(5, 8, 28, 29, 30) > y=c(5, 8, 28, 29, 31) > How can we compare these two vectors, whether each element is exactly matched with the elements in the other vector ? > How can we get the non matched elements from both the vectors? > Can anyone help? > ________________________________ > Notice: The information contained in this electronic mail message is intended only for the use of the designated recipient. This message is privileged and confidential. and the property of GVK BIO or its affiliates and subsidiaries. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone +91-40-66929999<tel:%2B91-40-66929999> and destroy any and all copies of this message in your possession (whether hard copies or electronically stored copies). > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Hi krishna, 1.How can we compare these two vectors,whether each element is exactly matched with the elements in the other vector? x=c(5, 8, 28, 29, 30) y=c(5, 8, 28, 29, 31) z<-(x %in% y)> z[1] TRUE TRUE TRUE TRUE FALSE (OR) z<-identical(x,y)> z[1] FALSE (OR) to get values that are matching z<-x[x %in% y]> z[1] 5 8 28 29 2.How can we get the non matched elements from both the vectors? z<-setdiff(x,y)> z[1] 30 i hope this will help Regards Ramakanth Reddy Guntuka --------------------------------------------------------------------------------------- Life Sc. Informatics Bonn-Aachen International Center for Information Technology University of Bonn, Germany Mob: +49-015141366412 On 8 August 2012 14:00, Sri krishna Devarayalu Balanagu < balanagudevarayulu@gvkbio.com> wrote:> x=c(5, 8, 28, 29, 30) > y=c(5, 8, 28, 29, 31) > How can we compare these two vectors, whether each element is exactly > matched with the elements in the other vector ? > How can we get the non matched elements from both the vectors? > Can anyone help? > ________________________________ > Notice: The information contained in this electronic mail message is > intended only for the use of the designated recipient. This message is > privileged and confidential. and the property of GVK BIO or its affiliates > and subsidiaries. If the reader of this message is not the intended > recipient or an agent responsible for delivering it to the intended > recipient, you are hereby notified that you have received this message in > error and that any review, dissemination, distribution, or copying of this > message is strictly prohibited. If you have received this communication in > error, please notify us immediately by telephone > +91-40-66929999<tel:%2B91-40-66929999> and destroy any and all copies of > this message in your possession (whether hard copies or electronically > stored copies). > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Herzlichen Gruß, Ramakanth Reddy Guntuka --------------------------------------------------------------------------------------- Life Sc. Informatics Programme Bonn-Aachen International Center for Information Technology University of Bonn, Germany Mob: +49-015141366412 [[alternative HTML version deleted]]
Seemingly Similar Threads
- How can I get the Ids with Duplicated key and corresponding Ids with original key?
- I want to send the vector a into the Object A.......
- How to find the non matching vectors among these five, if so how we can find the non matching element of that vectors?
- Why the result is coming as NULL?
- Why the error is coming, can anyone help?