0

I currently have data that is structured in the following way

ID,   Question, Answer   
abc,  123,      1,  
abc,  456,      2,  
abc,  789,      1,  
abc,  000,      4,  
def,  123,      2,  
def,  456,      3,  
def,  789,      1,    
def,  000,      2,  

I would like to convert it into a table format as follows

    123 456 789 000
abc  1   2   1   4  
def  2   3   1   2  

Basically with the ID as rows and the Question as columns.

What would be the most effective R code to achieve this?

Miha
  • 2,559
  • 2
  • 19
  • 34
alewis
  • 1
  • This is a simple long to wide conversion: use e.g. `library(tidyverse); df %>% group_by(ID) %>% spread(Question, Answer)`; lots of details/options/alternatives in the linked post. – Maurits Evers Aug 07 '18 at 11:43
  • 1
    Thank you Maurits for the answer and the link. Very helpful. – alewis Aug 08 '18 at 09:26

0 Answers0