Define the R function.
WeeklyUpdate <- function(x) {
profit <- x[,"salesprice"] - x[,"cost"]
i <- data.frame(x[,"date"], x[,"orderid"], x[,"itemid"], x[,"cost"], x[,"salesprice"], profit)
DailySales<-aggregate(x[,"salesprice"]~x[,"date"], i, sum)
DailyProfit<-aggregate(profit~x[,"date"], i, sum)
w <- data.frame(DailySales[,1], DailySales[,2], DailyProfit[,2])
colnames(w)<-c("Date","Total Sales", "Total Profit")
return(w)
}
Use the Aster R function aa.apply() to run the function created in Step 1, on the virtual data frame "tadf.fruit" created in Step 2.
aa.apply(tadf.fruit,
FUN = "WeeklyUpdate",
MARGIN = c(),
out.format=list(columns=c("Date", "Total Sales", "Total Profit"),
columnTypes=c("date", "numeric", "numeric")))
Date Total Sales Total Profit
1 5/1/2010 29.80 5.65
2 5/2/2010 31.78 6.80
3 5/3/2010 19.25 4.72
4 5/4/2010 20.57 5.72
For details about the arguments and options of the function aa.apply(), refer to the inline help.