I have a data frame (df) with 7 rows and 4 columns (named c1, c2, c3, c4):
c1 c2 c3 c4
Yes No Yes No
Yes Yes No No
No Yes No No
Yes No No
You could try something like:
colnames(df) <- c("c1", "c2", "c3", "c4")
test <- (apply(df,1,function(x) which(x=="Yes")))
df$cols <- lapply(test,names)
This was along the lines of what you were initially trying I think.
To tidy the output you could:
df$cols <- gsub("c(", "", df$cols, fixed = TRUE)
df$cols <- gsub(")", "", df$cols, fixed = TRUE)
This removes the c().