Here is one way of doing it:

> x <- "Name Date results
+ John 01/01/1991 2
+ John 02/01/1991 3
+ John 09/01/1991 4
+ Micheal 02/01/1991 4
+ Micheal 04/01/1991 5"
> x <- read.table(textConnection(x), header=TRUE, as.is=TRUE)
> x$Date <- as.POSIXct(strptime(x$Date, "%m/%d/%Y"))
> # earliest
> (early <- by(x, x$Name, function(.per) .per[which.min(.per$Date),]))
x$Name: John
  Name       Date results
1 John 1991-01-01       2
---------------------------------------------------------------------------------------------

x$Name: Micheal
     Name       Date results
4 Micheal 1991-02-01       4
> # latest
> (latest <- by(x, x$Name, function(.per) .per[which.max(.per$Date),]))
x$Name: John
  Name       Date results
3 John 1991-09-01       4
---------------------------------------------------------------------------------------------

x$Name: Micheal
     Name       Date results
5 Micheal 1991-04-01       5
>



On 6/19/07, Chung-hong Chan <chainsawtiney@gmail.com> wrote:
>
> Dear R experts,
>
> Suppose I have a data.frame recording the date and test results of
> some subjects like this:
>
> Name Date results
> John 01/01/1991 2
> John 02/01/1991 3
> John 09/0101991 4
> Micheal 02/01/1991 4
> Micheal 04/01/1991 5
> ....
>
> How to select the earliest (or latest) test result from all subjects?
>
> Thank you.
>
> Regards,
>
> CH
>
>
>
> --
> "The scientists of today think deeply instead of clearly. One must be
> sane to think clearly, but one can think deeply and be quite insane."
> Nikola Tesla
> http://www.macgrass.com
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

