I'm working on cleaning up my data for a university project, and I have two variables, DidVote and WouldVote, indicating who the person voted for (if they voted in the actual election) and who they would have voted for (if they did not vote in the election). These two columns are obviously complementary, meaning that if DidVote has some value, WouldVote is NA, and vice-versa. I want to merge these two variables into one, meaning I want to get something like the third column:
DidVote WouldVote Vote
x NA x
NA z z
NA y y
y NA y
I have tried to do the following:
data$Vote <- paste(data$DidVote,data$WouldVote)
But what I end up getting is:
DidVote WouldVote Vote
x NA x NA
NA z NA z
NA y NA y
y NA y NA
How can I merge the two columns such that the new variable takes the non NA value from each of the two variables DidVote and WouldVote?