I have a dataframe with multiple columns. The first column contains a unique identifier for a particular respondent; columns X1:n represent survey items where respondents are asked factual questions. A blank value signifies questions they answered correctly. Cells with character letters signify the incorrect option they had given (i.e., A through D). A simple example of the dataframe would be:
d <- data.frame('Name'=c("Res1","Res2","Res3"),'1'=c("A","","A"),'2'=c("","B",""), '3'=c("","C","E"), '4' = c("D","D",""))
For each row in the dataframe, I want to paste the questions they answered incorrectly with the corresponding question and selected answer into a single string variable. I can use this variable to provide feedback to participants regarding which questions they missed and their incorrect response.
I had originally tried the following using PASTE:
test4<- within(d, id<-paste(names(d[,2:5]), d[,2:5] ,sep = ".",collapse=","))
However, it didn't work.
What I ultimately want attached to the end of each row is a character string like this for row one (and for each row after}:
"1.A 4.D"