How can I collapse data in a wide format (see example below), into a concatenated column showing only the TRUE values? I want to end up with a data table in the format Employee Name | "string of applicable column headers" as illustrated in demoOUT
.
library(data.table)
demoIN <- data.table(
Name=c("Mike Jones","Bobby Fisher"),
A=c(1,0),
B=c(1,1),
C=c(0,0),
D=c(1,1))
Name A B C D
1: Mike Jones 1 1 0 1
2: Bobby Fisher 0 1 0 1
demoOUT <- data.table(
Name=c("Mike Jones","Bobby Fisher"),
Cases =c("A,B,D","B,D"))
Name Cases
1: Mike Jones A,B,D
2: Bobby Fisher B,D