supposing that these data are in a matrix, try this:

# you original data
M <- rbind(c(0,1,0,1), c(0,0,0,1), c(1,0,0,1))

V <- M # we make a copy...
V[V == 1] <- col(V)[V == 1]
V


I hope it helps.

Best,
Dimitris


On 4/13/2010 2:07 PM, burgundy wrote:

Hello,

I'm trying to replace cells with value 1 with the number of the column.
Example below.
Thank you!

from:
0,1,0,1
0,0,0,1
1,0,0,1

to:
0,2,0,4
0,0,0,4
1,0,0,4




--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to