[R] aggregate

From: Omar Lakkis <uofiowa_at_gmail.com>
Date: Wed 31 Aug 2005 - 00:36:50 EST


How can I aggregate this data.frame to list the min and max date for each unique id?

>From this :

> r = data.frame(id=rep(seq(1:3), 3), date= as.Date(c(rep("2005-08-25",3), rep("2005-08-26",3), rep("2005-08-29", 3)), "%Y-%m-%d"))
> r
id     date
 1     2005-08-25
 2     2005-08-25
 3     2005-08-25
 1     2005-08-26
 2     2005-08-26
 3     2005-08-26
 1     2005-08-29
 2     2005-08-29
 3     2005-08-29

I want to get to this:
>

id start end

 1    2005-08-25    2005-08-29
 2    2005-08-25    2005-08-29
 3    2005-08-25    2005-08-29

I tried aggregate and aggregate.data.frame but the date column keeps getting converted into a number.



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 Received on Wed Aug 31 00:43:10 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:00 EST