After downloading answers from Google Forms survey a problem related to multiple choice question emerged.
All answers to this question were coded in one variable/column and are separated by a comma. Unfortunatelly, I need to change them into 0-1 variables for each possible option. I managed to divide this "one variable" into different columns, but a specific answer/option can be found in various columns.
The code that I am using to create 0-1 variables is:
data$option1 <- ifelse(column1=='option1' || column2=='option1' || column3=='option1',1,0)
but it is very time-consuming as I have tens of columns and options.
Is there any way to do it in a loop using vectors with columns and options names? For example:
A <- c("column1", "column2", "column3", .....)
B <- c("option1", "option2", "option3", .....)
for (b in B){
for (a in A) {
Data$b <- ifelse (Data$a=='b',1,0)
}
}
I'm a beginner and I'm not sure how it should be done. I'll appreciate your help!