I've got the following data set:
data.frame(z, z, z, z, z, z, z,
item=letters[rep(24:26,2)]
,
freq=c(4,3,2,4,4,1),
id=rep(1:2,each=3)
)
item id freq
four times one
3 1 (y)
1 z
four times two
2 y
2 z
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
1 2 4 4
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) dcast(z,id,item,sum) dcast(z,i
and the following is the result:
id x y z id x y z id x y
1 1 1 1 1 1 1
2 2 2 2 2 2
What am I doing incorrectly?