[R] Aggregating dataset to means/day

From: OA Fatnes <ofa082_at_gmail.com>
Date: Wed, 16 Mar 2011 11:17:11 +0100


I have a dataset with many observations some days while only one others. I would like to calculate a mean value per day and then do regression analysis on the means.

This is what I have:

Year Day Time herring.density

2007    47     10.36           2.2
2007    47     11.50           1.1
2007    47     14.24           1.4
2007    66      9.35            2.5

This is what I want:

Year Day herring.density

2007     47         1.57
2007     66         2.25

I would also might like to extract means between time 10-16 (h) so that

Year Day herring.density
2007 47 1.25

Any idea on how to do this?

I have tried


Then I get means for every day, but means07 won't fit when plotted against days, because it is now shorter than Day. I also get a lot of NA values where there are only 1 observation that day...

Help would be much appreciated!


Ole Andreas

        [[alternative HTML version deleted]]

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 Wed 16 Mar 2011 - 12:58:54 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 Wed 16 Mar 2011 - 13:30:22 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