This seems to work fine:

> x <- "ca, la, 12
+ ca, sd, 22
+ ca, la, 33
+ nm, al, 9
+ ma, lx, 18
+ ma, bs, 90
+ ma, lx, 22
+ "
> table <- read.csv(textConnection(x), header=FALSE)
> aggregate(table$V3,list(table$V1,table$V2),mean)
  Group.1 Group.2    x
1      nm      al  9.0
2      ma      bs 90.0
3      ca      la 22.5
4      ma      lx 20.0
5      ca      sd 22.0
> aggregate(table$V3,list(table$V1,table$V2),sum)
  Group.1 Group.2  x
1      nm      al  9
2      ma      bs 90
3      ca      la 45
4      ma      lx 40
5      ca      sd 22
>



On 6/7/07, Guanrao Chen <guanrao@yahoo.com> wrote:
>
> Dear Fellow Rers,
>
> I have a table looks like this:
>
> ca, la, 12
> ca, sd, 22
> ca, la, 33
> nm, al, 9
> ma, lx, 18
> ma, bs, 90
> ma, lx, 22
>
> I want to sum the 3rd column grouped by the first and
> the second column, so the result look like this table:
>
> ca, la, 45 <
> ca, sd, 22
> nm, al, 9
> ma, lx, 40 <
> ma, bs, 90
>
> The two rows with < are sums.
>
> I tried
> aggregate(table,list(table$V1,table$V2),sum/mean), sum
> was not working while mean worked.
>
> Can anybody give a hint?
>
> Thanks.
> Guanrao
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

