Help-Rs
 
As someone who is newer to R and trying to make the transition from Access into R, there is a frequetnly used function that I'd like to try and duplicate in the R world.  It involved creating an aggregate table of the top (n)  orders for an item by sum of cost over a select period of time.
 
So, take the following example :
 
group <- c(rep(1,10), rep(2,10), rep(3,10))
product <- c(rep("itema", 4), rep("itemb", 2), rep("itemc", 1), rep("itemc" , 3), rep("itema", 4), rep("itemb", 2), rep("itemc", 1), rep("itemc", 3),rep("itema", 4), rep("itemb", 2), rep("itemc", 1), rep("itemc", 3))
cost <- round (rnorm(30, mean = 100, sd = 30), 2)
DF <- data.frame(group, product, cost)
agglist <- list(DF$product, DF$group)
col1<- aggregate(DF [,3], by = agglist, sum)
col2<- aggregate(aggDF [,3], by = agglist, length)
(table <- cbind(col1, col2))
 
My question would be, how about if you wanted a table that retained only the top 1 product (e.g., item c for group 2) by group... or for that matter the top n=2 or n=3 or n=5?  While with this example DF the answer would be easy to find, I'm dealing with millions of orders.
THX!
Chris
	[[alternative HTML version deleted]]

