have a dataset from a survey. 2 questions have multiple choice options and it doesn't allow me to use pivot_wider
here is a sample data.
nam=c("per_id","quest","answ")
per_id=c("0012","0023","0045","0003","0003","0045","0003","0012","0023","0004","0004","0001","0005","0546","0001","0546","0005","0004","0004")
quest=c("A","A","A","A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B")
answ=c("Self","Self","Self","Self","Father","Sister","Daughter","Mother","Father","Self","Father","X1","Y1","Z1","Y1","Z2","X1","X1","X1")
df=cbind.data.frame(per_id,quest,answ)
names(df)=nam
what I want to have is
You might try the following approach using
split
+Reduce
+merge
based on unique rows.Approach
Result
Data