Transforming dataset

r

#1

Am learning stats and R . Here a data manipulation question which I am not able to figure out how to do it in R. Here is dataframe output

head(mydata)
Coast Menu Sales
1 East Item1 25
2 East Item1 36
3 East Item1 31
4 East Item1 26
5 East Item2 39
6 East Item2 42

I want to convert into dataset with columns ( Item1, Item2…) and rows as (East, West …) and Sales data fitted into this matrix.

I tried using melt and cast but not successful.
What could be efficient code to perform this transformation?

Regards
Amber


#2

@ambergupta Try this -

library(reshape2)
dcast(mydata,Coast ~ Menu, value.var = 'Sales')