have a look at function all() but also at function all.equal() -- for your example,

x1 <- c(1,2,3)
x2 <- c(1,2,3)
x3 <- c(1,2,5)

all(x1 == x2)
all(x1 == x3)

# this safer
isTRUE(all.equal(x1, x2))
isTRUE(all.equal(x1, x3))


I hope it helps.

Best,
Dimitris


On 8/13/2010 8:49 PM, Downey, Patrick wrote:
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@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.


--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

______________________________________________
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.

Reply via email to