RE: [R] How to compare X1 = X2 = ... = Xn?

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Tue 20 Jul 2004 - 04:38:39 EST


Stupid me: fell into this trap:

> 0 == 0 == 0

[1] FALSE Andy

> From: Sundar Dorai-Raj
>
> Liaw, Andy wrote:
>
> > Here's an alternative:
> >
> >
> >>x <- data.frame(X1 = c(1, 1, 2, 4),
> >
> > + X2 = c(4, 1, 2, 5),
> > + X3 = c(2, 1, 2, 2))
> >
> >>check <- paste(names(x), collapse=" == ")
> >>with(x, eval(parse(text=check)))
> >
> > [1] FALSE TRUE FALSE FALSE
>
> Oops. Should be
>
> > [1] FALSE TRUE TRUE FALSE
>
> This is TRUE for the second case by accident since the second
> element is 1.
>
> > x$X4 <- (x$X1 == x$X2)
> > as.numeric(x$X4)
> [1] 0 1 1 0
> > x$X4 == x$X3
> [1] FALSE TRUE FALSE FALSE
> >
>
>
>

>



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jul 20 04:58:08 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 02:36:54 EST