maybe you could use something like this:
dat <- data.frame(id = rep(1:3, 3), date =
as.Date(rep(c("2005-08-25",
"2005-08-26", "2005-08-29"), each = 3)))
########################
do.call("rbind", lapply(split(dat, dat$id), function(x) data.frame(id
= x$id[1], start = min(x$date), end = max(x$date))))
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Omar Lakkis" <uofiowa at gmail.com>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, August 30, 2005 4:36 PM
Subject: [R] aggregate
> 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 at 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
>