>From what I read this should work. So please help my misunderstanding:

> x <- data.frame(Name=c("A","A","C"), Category=c("a","a","b"), 
> Quantity=c(1,2,3))
> x
  Name Category Quantity
1    A        a        1
2    A        a        2
3    C        b        3

> aggregate(x, by=as.list(setdiff(names(x),"Quantity")), sum)
Error in FUN(X[[1L]], ...) : arguments must have same length

The way I understand it is that 'aggegate' should group the rows that are the 
same (in the above 1,2 are the same and 3 stands alone) and the FUN should be 
applied to the ramaining column. I was expecting a data.frame like:

  Name Category Quantity
1   A        a          3
2   C         b         3

But that is not what I got. Would someone be so kind as pointing out what I am 
doing wrong?

Thank you.

Kevin

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to