I've got the following data set:
z - data.frame(item=letters[rep(24:26,2)], freq=c(4,3,2,4,4,1), id=rep(1:2,each=3), freq=c(4,3,2,4,4,1), id=rep(1:2,each=3) )
item freq id multiplied by four 1 z 2 y 3 y 3 y 3 y 3 y 3 y 3 1 x 4 2 y 4 2 z 1 2 x 4 2 y 4 2 z 1 2 x 4 2 y 4 2
Every id/item combination results in a unique data frame.
This is how I'd like it to be:
id x y z id x y z id x y
1 4 3 2 2 4 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
This appears to be a fairly straightforward transformation, but I can't manage to get it to work.
Here's what I came up with (the data frame's name is z):
dcast(z,id,item,sum) yields the following:
1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
What am I doing incorrectly?