[R] How to compare X1 = X2 = ... = Xn?
Uwe Ligges
ligges at statistik.uni-dortmund.de
Mon Jul 19 20:06:16 CEST 2004
F Duan wrote:
> Dear All,
>
>
>
> 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.
>
One idea is:
apply(apply(X, 2, "==", X[,1]), 1, all)
but there may be better solutions.
Uwe Ligges
>
> How to do that in a quick way instead of doing (n choose 2) comparisons?
>
>
>
> Thank you,
>
>
>
> Frank
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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
More information about the R-help
mailing list