[R] Identify first row of each ID within a data frame, create a variable first =1 for the first row and first=0 of all other rows
Boris Steipe
bor|@@@te|pe @end|ng |rom utoronto@c@
Sun Dec 1 13:46:06 CET 2024
olddata$first <- as.numeric(! duplicated(olddata$ID))
:-)
> On Nov 30, 2024, at 22:27, Sorkin, John <jsorkin using som.umaryland.edu> wrote:
>
> 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))
> olddata <- data.frame(ID=ID,date=date)
> class(olddata)
More information about the R-help
mailing list