[R] add an idx column to the matrix
Lida Zeighami
lid.zigh at gmail.com
Mon Aug 10 22:11:10 CEST 2015
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]]
More information about the R-help
mailing list