On Fri, May 04, 2012 at 12:53:12AM -0700, aaurouss wrote: > Hello, > > I'm writing a piece of code where I need to compare multiple same length > vectors. > > I've gone through the basic functions like identical() or all(), but they > only work for comparing 2 vectors. From 3 vectors on, it doesn't work . > > Example: Assuming > vec1 <- c (1,2,3,4,5) > vec2 <- c(1,2,3,4,5) > vec3 <- c(1,2,3,4,4) > > identical (vec1,vec2,vec3) returns TRUE, since the 2 first vectors are > equal. I need a function that returns FALSE if one of the vectors is > different.
Hi. Try the following. length(unique(list(vec1, vec2, vec3))) == 1 [1] FALSE length(unique(list(vec1, vec2, vec1))) == 1 [1] TRUE Hope this helps. Petr Savicky. ______________________________________________ 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.