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
An option using data.table
data.table
library(data.table) setDT(df)[, rownum:=1:.N,] df$Expected_result <- melt(df, "rownum")[, toString(variable[value=="Yes"]), rownum]$V1