[R] Equality of Vectors

Derek Ogle DOgle at northland.edu
Fri Aug 13 20:53:09 CEST 2010


Patrick,

See all().  For example,

> all(c(1,2,3)==c(1,2,3))
[1] TRUE
> all(c(1,2,3)==c(2,1,3))
[1] FALSE


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Downey, Patrick
> Sent: Friday, August 13, 2010 1:49 PM
> To: r-help at r-project.org
> Subject: [R] Equality of Vectors
> 
> Hello,
> 
> Is there a way to get a single TRUE or FALSE statement from comparing
> two
> vectors? For example,
> c(1,2,3) == c(1,2,3)
> produces
> TRUE TRUE TRUE
> 
> where I would like it to produce only
> TRUE
> for use in an if statement.
> 
> Likewise, when two vectors are not exactly identical (in all elements)
> I
> would like a single FALSE result, as opposed to
> c(1,2,3) == c(1,2,5)
> TRUE TRUE FALSE
> 
> Any ideas?
> 
> Thanks,
> Mitch
> 
> ______________________________________________
> 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.



More information about the R-help mailing list