I cannot find a thread which answers this specific question, so help would be appreciated. I have a dataset that looks like this, where the variable 'EventCount' counts the number of days between events occurring for each person in the dataset (if EventCount=0, then event has occurred).
Day = c(1:8,1:8)
EventCount = c(NA,NA,0,1,2,0,1,0,0,1,2,3,0,1,2,0)
Person = c(1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2)
dat <- data.frame(Person,Day,EventCount);dat
I am trying to restructure the dataset so that it takes the maximum value BETWEEN events occurring for each person, and copies or fills that value. I want it to look like this:
NewEvent = c(NA,NA,0,2,2,0,1,0,0,3,3,3,0,2,2,0)
dat2 <- dat <- data.frame(Person,Day,NewEvent);dat2
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire