I am working on a dataset (namely w3) in R that looks like this:
Q1 Q2 Q3 Q4 WorksheetID UserID
395 2178 2699 1494 3 65
395 2178 2694 1394 3 78
395 1178 2699 1394 3 79
395 278 2699 1394 3 80
295 1188 2799 1494 3 81
395 2278 2699 2394 3 81
395 2178 2699 1394 3 83
495 1178 2709 1394 3 84
395 2198 2799 1294 3 85
395 2178 2699 1394 3 85
395 1178 2699 1394 3 86
Each User has answered 4 questions(Q1,Q2,Q3,Q4) of the worksheet.
What I want to do is to group the users according to the answers the answered in each Question.
e.g. for Q1
Q1 freq UserID
295 1 81
395 9 65 78 79 80 81 83 85 85 86
495 1 84
What I have done is
w3Q1<-count(W3,"Q1")
for(i in w3Q1$Q1)
{qry<-paste('select userID from w3 where Q1=',i)
print(i)
print(sqldf(qry))}
My question is, how do I combine the above results and turn it into the table with the variables Q1, freq, UserID (as shown above)? Or is there any simpler way?
Thanks a lot