Skip to content

Convert long to wide

davidstillwell edited this page Jul 16, 2016 · 12 revisions

Concerto saves data in long format like this (Example from default data table):

There are good reasons for this. Long format is better for databases because if there's a new question you don't need to change the structure of the database. This is important if you've got a large dataset because it can take a long time to change the database structure, during which the database is unavailable for use. Also, imagine an adaptive test with 1,000 items in the item bank. You don't really want a data table 1000 columns wide, when each person might only answer 10 items.

So how do you convert the resulting data to wide format, ready to analyse? Most statistical packages will have options for this; try searching Google for convert long data to wide data.

One way to do it in R is:

#import data
mydata  = read.csv('C:/Users/David/Desktop/default_data_table.csv', as.is=TRUE, stringsAsFactors=FALSE) 

#tidyr has a nice function to do reshaping
library(tidyr) 

#convert to wide data
mydata_wide = spread(mydata, name, value) 

And here's the example default_data_table.csv file that is screenshotted above.

Clone this wiki locally