Hi there, I have a matrix contain 0,1,2, NA elements. I want to add a column to this matrix with name of "idx" . then for each row, I should put 1 in this column (idx) if there is at least one 2 in that row otherwise I should put 0 in this column!
for example mydata: 125 255 558 2366 177 255 aa 0 1 0 NA 0 0 bb 1 1 0 NA 0 1 cs 2 1 2 1 0 0 de 0 1 0 NA 0 0 gh 2 0 0 0 0 0 my output should be: 125 255 558 2366 177 255 idx aa 0 1 0 NA 0 0 0 bb 1 1 0 NA 0 1 0 cs 2 1 2 1 0 0 1 de 0 1 0 NA 0 0 0 gh 2 0 0 2 0 2 1 Thank you for your help. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.