[R] Fwd: Matching when each subject has multiple records

Naresh Gurbuxani n@re@h_gurbux@n| @end|ng |rom hotm@||@com
Thu Sep 18 16:10:29 CEST 2025




> mydf <- data.frame(date = as.Date("2010-01-01") + sample(500, size = 20), subject = sample(c("A", "B", "C"), 20, replace = TRUE), first = FALSE)
> mydf <- mydf[order(mydf$date),]
> df_split <- split(mydf, f = mydf$subject)
> df_split <- lapply(df_split, function(df) {df[1, "first"] <- TRUE; df})
> mydf <- do.call(rbind, df_split)


	[[alternative HTML version deleted]]



More information about the R-help mailing list