0

I am trying to change my data from long to wide format. It is a factorial design with one between subject and two within subject variables.

My data: https://drive.google.com/file/d/0B9lnMw6dkH9KZUZKQkh4M3BIbGM/view?usp=sharing

enter image description here

When I try

library(reshape2)
data.wide<- dcast(correct.anal,group+subnum~speed+int, value.var="corr") 

on the data, it says

Aggregation function missing: defaulting to length

I do not have duplicate values though so I do not understand what I need to do.

What I want to achieve is to get from my current data to output one line per subject with 22 columns (subnum, group and the twenty combinations).

Can anyone help with that?

jbest
  • 640
  • 1
  • 10
  • 28
Maja
  • 1
  • Welcome. It's preferable if you post a subset of your data into your question in a way that makes it easy for copying/pasting (not linking to an external source). See how to [provide a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Also good to format your code with control + K to make it easier to read. – LJW Dec 04 '14 at 23:20
  • I was unable to replicate the problem with sample data that looks like the picture of your data. I did not download the file you linked. There may be a problem in your data file where there is more than one value per subject/group combo. [See the comment here for an explanation.](http://stackoverflow.com/questions/8093839/reshape-data-for-values-in-one-column#comment9931762_8094656) – LJW Dec 04 '14 at 23:56
  • @LJW, you can download the data save it as txt, replace "," with "." then import the data to R with sep=";" – jbest Dec 05 '14 at 02:42
  • @Maja can you provide me a sample of the outcome you want. Thank you. – jbest Dec 05 '14 at 02:43
  • @Maja the error is telling you that you can have duplicate column names when you used dcast function. You need to used aggregate command first to make them unique – jbest Dec 05 '14 at 02:53

1 Answers1

0

Perhaps this can help:

data.wide<- dcast(correct.anal,group+subnum~speed+int,fun.aggregate=mean, value.var="corr")

I just add the fun.aggregate=mean to average the duplicates.

jbest
  • 640
  • 1
  • 10
  • 28