I have a df. If 'info' appears in a row, I would like a function to take the column-name and and paste it together with the information from the cell with a '=' between them. I have tried the function below, which works, except that it does not refer to the columnname from the right column
df <- data.frame('criteria1' = c('info','1', 'info', '', 'info'), "criteria2" = c('y','3', '', 'info', ''), "criteria3" = c('y','7', '', 'info', 'info'))
df[] <- sapply(df, function(x) ifelse(x == 'info', paste(colnames(df)[x], ' = ', x),''))
My expected output is something like this (it does not matter if the columnnames are deleted, it is just the info from the cells that are important)
df_exp <- data.frame('criteria1' = c('criteria1= info','', 'criteria1=info', '', 'criteria1 =info'), "criteria2" = c('','', '', 'criteria2 = info', ''), "criteria3" = c('','', '', 'criteria3 = info', 'criteria3 = info'))