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?
Jun 19, 2022 299 views

## 1 answer to this question.

```> dcast(z, id ~ item, value.var="freq")
id x y z
1  1 4 3 2
2  2 4 4 1```

Unleash the power of data with our comprehensive Data Science Training.

• 3,040 points

## To speed up the tapply function in R, or another function to convert data frame into a matrix

I must turn a sizable dataset into ...READ MORE

## How to establish a connection to a remote Redash database using R?

To connect to a Redash database using ...READ MORE

## Converting xlsx to xls using Microsoft Office Compitablity Pack's excelcnv

Simply rearranging the positions of the parameters ...READ MORE

## Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

## Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

The below is the code to perform ...READ MORE