[R] Reshape set operations?

rkevinburton at charter.net rkevinburton at charter.net
Sat Aug 9 18:44:15 CEST 2008


I have mange to use the library reshape to give me data structures that I want. Specifically:

m2008 <- melt(t2008, id.var=c("DayOfYear","Category","SubCategory","Sku"), measure.var=c("Quantity"))
 m2007 <- melt(t2007, id.var=c("DayOfYear","Category","SubCategory","Sku"), measure.var=c("Quantity"))

 r2008 <- cast(m2008, DayOfYear ~ variable | Sku, sum)
 r2007 <- cast(m2007, DayOfYear ~ variable | Sku, sum)

Now I would like to union the two lists. So I start out with an empty master list that will contain (when I am done) the merge (union) of r2008 and r2007. By "union" I mean that if the Sku exists in r2007 and r2008 I would like to create a new data frame that has the lists for DayOfYear and Quantity "merged" and append it to 'master'. If the Sku is not common to both objects then just copy or append to the 'master'.

Is it possible to come up with an expression and aggregate function that will do this? Is this better handle with aggregate functions or lapply? Being new to 'R' it is hard for me to tell.

Thank you.

Kevin



More information about the R-help mailing list