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

From: Gabor Grothendieck <ggrothendieck_at_myway.com>
Date: Tue 20 Jul 2004 - 04:48:47 EST

Gabor Grothendieck <ggrothendieck <at> myway.com> writes:

:
: F Duan <f.duan <at> yale.edu> writes:
:
: > I have a data frame with n columns: X1, X2, ., Xn. Now I want to create a
: > new column: if X1 = X2 = . = Xn, the value is 1; Otherwise, the value is 0.
:
: Here is one possibility if your data frame is all numeric:
:
: x$new <- (sd(t(x))==0)+0
:
: x is the data frame, new is the new column, sd(t(x)) is TRUE for
: rows with zero standard deviation (which occurs iff the entries
: are all zero) and FALSE otherwise and +0 converts that to 1 or 0.

          ^^^^

"zero" should be replaced by "the same".



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 05:10:55 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:05 EST