[R] question on aggregate

Altaweel, Mark R. maltaweel at anl.gov
Fri May 1 23:07:30 CEST 2009


Hi,

I am trying to sum column information in a list with 3 instances.

For example:


ID   Traversed           ID    Traversed      ID    Traversed
1      5                          1       7                    1       8
2      8                          2       11                  2       7
3      11                        3       22                  3       16

What I want to do is sum the Traversed variable across all these instances so I can get a total value for Traversed for each ID column. So the end output should look like the following:

ID    Traversed
1      20
2      26
3      49

Basically, just sum up the columns by id.

I am using the aggregate function, but it is not working.

This is what I do:
agW<-aggregate(rres,rres[c('ID')],sum) //rres is the list
Error in FUN(X[[1L]], ...) : argument "INDEX" is missing, with no default    //the error message I get

As you can see, I get the index error when I try this above.

Can anyone help?

Thanks in advance.

Mark




More information about the R-help mailing list