Sri krishna Devarayalu Balanagu
2012-Sep-06 08:40 UTC
[R] How to find the non matching vectors among these five, if so how we can find the non matching element of that vectors?
Hello, Say all the below five vectors should have same elements in any situation. How to find the non matching vectors among these five, if so how we can find the non matching elements of those vectors? Can anyone help? a=c(1,2,3) b=c(1,2,3,4) c=c(1,2,3) d=c(1,2,3) e=c(1,4,5) identical(a,b,c,d,e) Visit us at Booth No. 5 at 2012 ChemOutsourcing Conference, 10-13 Sept 2012, Ocean Place Resort - Long Branch, NJ, United States Visit us at Booth No. 4 at World Conference on Pharmacometrics, 5-7 Sept 2012, Grand Hilton Hotel, Seoul, Korea ________________________________ 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]]
Richard M. Heiberger
2012-Sep-06 18:11 UTC
[R] How to find the non matching vectors among these five, if so how we can find the non matching element of that vectors?
This should get you started. Rich aa <- c(1,2,3) bb <- c(1,2,3,4) cc <- c(1,2,3) dd <- c(1,2,3) ee <- c(1,4,5) outer.all.equal <- function(input.list) { nn <- names(input.list) if (is.null(nn)) stop("input must be a named list.") n <- length(input.list) result <- vector("list", n*n) dim(result) <- c(n, n) dimnames(result) <- list(nn, nn) for (i in nn) for (j in nn) result[[i, j]] <- all.equal(input.list[[i]], input.list[[j]]) result } outer.all.equal.TRUE <- function(x) { y <- array(vector(length=length(x)), dim(x), dimnames(x)) y[] <- sapply(result, function(x) length(x)==1 && x == TRUE) y } input.list <- list(aa=aa, bb=bb, cc=cc, dd=dd, ee=ee) result <- outer.all.equal(input.list) result str(result) outer.all.equal.TRUE(result) On 9/6/12, Sri krishna Devarayalu Balanagu <balanagudevarayulu at gvkbio.com> wrote:> Hello, > > Say all the below five vectors should have same elements in any situation. > How to find the non matching vectors among these five, if so how we can find > the non matching elements of those vectors? > Can anyone help? > > a=c(1,2,3) > b=c(1,2,3,4) > c=c(1,2,3) > d=c(1,2,3) > e=c(1,4,5) > identical(a,b,c,d,e) > Visit us at Booth No. 5 at 2012 ChemOutsourcing Conference, 10-13 Sept 2012, > Ocean Place Resort - Long Branch, NJ, United States > > Visit us at Booth No. 4 at World Conference on Pharmacometrics, 5-7 Sept > 2012, Grand Hilton Hotel, Seoul, Korea > ________________________________ > 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. >
David Winsemius
2012-Sep-06 18:20 UTC
[R] How to find the non matching vectors among these five, if so how we can find the non matching element of that vectors?
On Sep 6, 2012, at 1:40 AM, Sri krishna Devarayalu Balanagu wrote:> Hello, > > Say all the below five vectors should have same elements in any situation. > How to find the non matching vectors among these five, if so how we can find the non matching elements of those vectors?"non-matching" is not a well-defined mathematical expression. What is the "right answer" to you question?> Can anyone help? > > a=c(1,2,3) > b=c(1,2,3,4) > c=c(1,2,3) > d=c(1,2,3) > e=c(1,4,5) > identical(a,b,c,d,e)The `identical function only takes two arguments. For instance, does majority rule if there are multiple duplicated items?> a=c(1,2,3) > b=c(1,2,3,4) > c=c(1,2,3) > d=c(1,2,3) > e=c(1,2,3,4)This will identify the items that are identical to the first duplicated item: list(a=a,b=b,c=c,d=d,e=e) %in% list(a=a,b=b,c=c,d=d,e=e)[duplicated( list(a=a,b=b,c=c,d=d,e=e) )][1] [1] TRUE FALSE TRUE TRUE FALSE -- David Winsemius, MD Alameda, CA, USA
arun
2012-Sep-06 22:41 UTC
[R] How to find the non matching vectors among these five, if so how we can find the non matching element of that vectors?
Hi, Try this: list1<-list(a=a,b=b,c=c,d=d,e=e) dat1<-as.matrix(do.call(rbind,lapply(list1,`[`,1:4))) dat1[duplicated(dat1)|duplicated(dat1,fromLast=TRUE),] ? [,1] [,2] [,3] [,4] #a??? 1??? 2??? 3?? NA #c??? 1??? 2??? 3?? NA #d??? 1??? 2??? 3?? NA dat1[!(duplicated(dat1)|duplicated(dat1,fromLast=TRUE)),] ? #[,1] [,2] [,3] [,4] #b??? 1??? 2??? 3??? 4 #e??? 1??? 4??? 5?? NA which(!(duplicated(dat1)|duplicated(dat1,fromLast=TRUE))) #[1] 2 5 dat2<-dat1[!(duplicated(dat1)|duplicated(dat1,fromLast=TRUE)),] ?do.call(rbind,apply(dat2,2,function(x)x[!(duplicated(x)|duplicated(x,fromLast=TRUE))])) ???? b? e #[1,] 2? 4 #[2,] 3? 5 #[3,] 4 NA A.K. ----- Original Message ----- From: Sri krishna Devarayalu Balanagu <balanagudevarayulu at gvkbio.com> To: "r-help at r-project.org" <r-help at r-project.org> Cc: Sent: Thursday, September 6, 2012 4:40 AM Subject: [R] How to find the non matching vectors among these five, if so how we can find the non matching element of that vectors? Hello, Say all the below five vectors should have same elements in any situation. How to find the non matching vectors among these five, if so how we can find the non matching elements of those vectors? Can anyone help? a=c(1,2,3) b=c(1,2,3,4) c=c(1,2,3) d=c(1,2,3) e=c(1,4,5) identical(a,b,c,d,e) Visit us at Booth No. 5 at 2012 ChemOutsourcing Conference, 10-13 Sept 2012, Ocean Place Resort - Long Branch, NJ, United States Visit us at Booth No. 4 at World Conference on Pharmacometrics, 5-7 Sept 2012, Grand Hilton Hotel, Seoul, Korea ________________________________ 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.
Reasonably Related Threads
- Why the error is coming, can anyone help?
- How can I get the Ids with Duplicated key and corresponding Ids with original key?
- How can we compare two vectors?
- I want to send the vector a into the Object A.......
- How can we compare corresponding values of x and y (first value of x exacly matches with the first value of y)?