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. ______________________________________________ [EMAIL PROTECTED] 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