[R] RESHAPE cast help.
rkevinburton at charter.net
rkevinburton at charter.net
Tue Aug 5 19:59:35 CEST 2008
I have a set of data that is basically sales figures for a given year. It has columns for Yeaqr, Day Of Year, Sku, SubCatetory, and Category. The first few lines of data look like:
Year DayOfYear Sku Quantity CatId Category SubCategory
1 2007 1 100091 1 10862 HOLIDAY Christmas
2 2007 1 100138 1 11160 PET COSTUMES Famous (Licensed)
3 2007 1 100194 1 10749 HATS, WIGS & MASKS Wigs - Women's
4 2007 1 100432 1 10865 HOLIDAY Easter
5 2007 1 100911 1 10120 MEN Superheroes Men
So I have the following to help me summarize the data by the various columns:
library("reshape")
t <- melt(t2007, id.var=c("DayOfYear","Category","SubCategory","Sku"), measure.var=c("Quantity"))
The following seems to give me the sales for each day of the year:
head(cast(t, DayOfYear ~ variable, sum))
DayOfYear Quantity
1 1 861
2 2 1732
3 3 2124
4 4 1801
5 5 2147
6 6 1312
Now I want to get the sales by day of year AND category. But the following doesnt seem right:
head(cast(t, DayOfYear ~ Category ~ variable, sum))
[1] NA 2 NA NA 2 NA
For one the category name doesn't seem to be listed. I am not sure what this output shows me. Any help? Ideally I would like to have for each day of year a list of each category that a sale was made (given by the quantity, the mearsure variable)
Thank you.
Kevin
More information about the R-help
mailing list