So I have a dataframe with results of the survey. The thing is, I have several questions with multiple answers in cell. For example:
q1|q2
answer1;answer2;ansert4 |1986
so I need to extract 'tidy' dataset for specific analysis tasks, meaning: split those cells down in the same column and copy other specified columns so it will be like that:
q1|q2
answer1|1986
answer2|1986
answer4|1986
How can i do this in R? I am pretty sure it is a simple task, but I don't have any clue...
Another similar solution would be
library(splitstackshape)
cSplit(df, "q1", sep = ";", direction = "long")
# q1 q2
# 1: answer1 1986
# 2: answer2 1986
# 3: ansert4 1986
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With