I am trying to convert some columns containing either 1 or 0 to a comma separated list with its column names.
More specific, with an example:
df <- data.frame(id = c(1, 2, 3, 4), A = c("0", "1", "1", "0"), B = c("1", "1", "0", "0"), C = c("0", "0", "1", "1"))
If columns A, B and C are equal to 1, a new "list" column containing all comma separated "tags" (column names) should be created.
id A B C
1 0 1 0
2 1 1 0
3 1 0 1
4 0 0 1
Desired result:
id A B C list
1 0 1 0 B
2 1 1 0 A, B
3 1 0 1 A, C
4 0 0 1 C