Using dcast to widen a data frame

0 votes
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?
Jun 20, 2022 in Data Analytics by Avinash
• 1,260 points

edited Mar 4 12 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP