Skip to content
Prev 280889 / 398506 Next

Recoding multiple TRUE/FALSE columns into a single list of TRUE columns

Try this:
+ 1   0    0    1    1
+ 2   0    1    1    1
+ 3   1    0    0    0
+ 4   0    0    0    0
+ 5   1    1    1    1  ", header = TRUE)
+     indx <- which(.row == 1)
+     if (length(indx) > 0) return(paste(names(x)[indx], collapse = ','))
+     else return(NA)
+ })
P1 P2 P3 P4      result
1  0  0  1  1       P3,P4
2  0  1  1  1    P2,P3,P4
3  1  0  0  0          P1
4  0  0  0  0        <NA>
5  1  1  1  1 P1,P2,P3,P4

        
On Sun, Dec 25, 2011 at 7:30 PM, David Epstein <davideps at umich.edu> wrote: