0

I have a matrix with of 1's and 0's. I want to replace all the 1's by an identifier code for that row (the identifier code is given in row 2)

I tried:

dax[,2:109] <- replace(dax[,2:109],dax[,2:109]==1,dax[2,])

but this isn't working right. I've tried to set up a loop, but I've had no success so far.

I'm new to R. Any help is appreciated

Jilber Urbina
  • 53,125
  • 10
  • 108
  • 134
lever
  • 614
  • 1
  • 5
  • 10

1 Answers1

0

This may do it for you, although it'd be nice to get more details from you.

for(j in 2:109) dax[dax[,j]==1,j] <- dax[2,j]
Carl Witthoft
  • 20,036
  • 8
  • 41
  • 71