Skip to content

Aggregating a List

2 messages · Paul Boutros, Peter Dalgaard

#
Hi all,

There must be a really obvious R solution to this, but I can't figure out
how to aggregate a list.  For instance, if I read.table the following from
a file:
	Val1	Val2
A	3	4
A	5	6
B	4	4

I would like to take the mean (or median) across any/all rows of type "A"
to end up with the structure:

	Val1	Val2
A	4	5
B	4	4

in this case.  How would I go about doign that w/o doing a loop or putting
into a DB and using SQL to do this?

Thanks for any suggestions, or pointers at appropriate functions I should
be reading the documentation on.

Paul

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Paul Boutros <pcboutro at engmail.uwaterloo.ca> writes:
aggregate()

E.g.,
0: gr         Val1    Val2
1: A       3       4
2: A       5       6
3: B       4       4
4:
gr Val1 Val2
1  A    3    4
2  A    5    6
3  B    4    4
Group.1 Val1 Val2
1       A    4    5
2       B    4    4

or for that matter: aggregate(g[-1],g[1],mean)