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

F Duan f.duan at yale.edu
Mon Jul 19 21:08:57 CEST 2004


Thanks for all your quick answers.

That's exactly what I want.

Best, 

Frank

-----Original Message-----
From: Berton Gunter [mailto:gunter.berton at gene.com] 
Sent: Monday, July 19, 2004 14:32
To: F Duan; R-Help
Subject: Re: [R] How to compare X1 = X2 = ... = Xn?

How about:


X<-as.matrix(yourframe)
apply(X,2, '==',X[,1])%*%rep(1,ncol(X)) == ncol(x)

avoiding the rowwise apply overhead?

Cheers,

Bert Gunter

Non-Clinical Biostatistics
Genentech
MS: 240B
Phone: 650-467-7374


"The business of the statistician is to catalyze the scientific learning
process."

 -- George E.P. Box
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.
>
>
>
> 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