In addition to many good solutions already provided, this solution uses 
data.table package.

library(data.table)
mydf <- data.frame(id = c(rep(1,10),rep(2,6),rep(3,2)), date = 
c(rep(1,2),rep(2,2),rep(3,2),rep(4,2),rep(5,2), rep(5,3),rep(6,3),rep(10,2)))
setDT(mydf)
mydf[, `:=`(firstdate = with(.SD, min(date))), by = .(id)]
setDF(mydf)

On Nov 27, 2024, at 11:30 AM, Sorkin, John <jsor...@som.umaryland.edu> wrote:

c(rep(1,2),rep(2,2),rep(3,2),rep(4,2),rep(5,2),
         rep(5,3),rep(6,3),rep(10,2))


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to