[R] aggregate(), with multiple functions in FUN?

From: Mike ! <mc510_at_hotmail.com>
Date: Fri, 16 May 2008 14:18:07 +0000

I've got a data frame having numerical data by zip code:

ZIP         DATA
94111     12135.545
93105     321354.65654
94111     545.555
94706     558858.66

... ...

I'm using this function to group records by ZIP and calculate the median of DATA:

aggregate(d$DATA, list(Zip = d$ZIP), FUN=median, na.rm=T)

but what I really want to do is to calculate several statistics (median, mean, etc.) for each group of records, so that I'll get a result organized like:

Zip       median(DATA)    mean(DATA)
94706   565                    555
94111   59585                 66666
93105   595685               5555666

...

I tried using FUN=funstofun(median,mean), but found that doesn't work in aggregate. Is there a straightforward way to do what I'm after (I'm pretty new to R)? thanks



Change the world with e-mail. Join the iím Initiative from Microsoft.

ld



R-help_at_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. Received on Fri 16 May 2008 - 14:22:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 18 May 2008 - 02:30:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive