Skip to content
Prev 76035 / 398502 Next

Seeking help with an apparently simple recoding problem

On Tue, 2005-08-23 at 10:12 -0500, Greg Blevins wrote:
You left out one key detail in the explanation, which is that the
recoding appears to be done on a row by row basis, not overall.

The following gets the job done, though there may be a more efficient
approach:
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
a    1    0    1    0    0    0    0
b    1    1    1    1    0    0    0
c    1    1    0    1    0    0    0
{
   if (all(x[c(2, 4:7)] == 0))
   {
     x[2:7] <- NA
     x[1] <- 2
   } else {
       x[3] <- NA
   }
 
   x
 }
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
a    2   NA   NA   NA   NA   NA   NA
b    1    1   NA    1    0    0    0
c    1    1   NA    1    0    0    0


HTH,

Marc Schwartz