[R] Subset by Factor by date

From: T.D.Rudolph <prairie.picker_at_gmail.com>
Date: Fri, 13 Jun 2008 21:10:36 -0700 (PDT)

I have a dataframe, x, with over 60,000 rows that contains one Factor, "id", with 27 levels.
The dataframe contains numerous continuous values (along column "diff") per day (column "date") for every level of id. I would like to select only one row per animal per day, i.e. that containing the minimum value of "diff", along the full length of 1:nrow(x). I am not yet able to conduct anything beyond the simplest of functions and I was hoping someone could suggest an effective way of producing this output.

e.g. given this input:

id day diff

1  01-01-09  0.5
1  01-01-09  0.7
2  01-01-09  0.2
2  01-01-09  0.4
1  01-02-09  0.1
1  01-02-09  0.3
2  01-02-09  0.3
2  01-02-09  0.4

I would like to produce this output:
id day          diff
1  01-01-09  0.5
2  01-01-09  0.2

1 01-02-09 0.1
2 01-02-09 0.3

It doesn't seem extremely difficult but I'm sure there are easier ways than how I am currently approaching it!

View this message in context: http://www.nabble.com/Subset-by-Factor-by-date-tp17835631p17835631.html
Sent from the R help mailing list archive at Nabble.com.

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 14 Jun 2008 - 04:51:50 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 Sat 14 Jun 2008 - 05:30:40 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