The data frame I have looked like this.
"rank" variable has to be increased once the differences between the [i]th row of "start" and the [i-1]th row of "end" are over 14.(also, when encountered the different "ID")
I tried the code below and it worked very well.
But the thing is.. it is way too slow because I have like over 700000 rows.
So, is there any way to make it perform much faster?
df$rank <- 1
for(i in 2:nrow(l50.df)){
df[i,"rank"] <- ifelse((df[i,"ID"]==df[i-1,"ID"])&
(df[i-1,"diff"]<=14),
df[i,"rank"] <- df[i-1,"rank"],
df[i,"rank"] <- df[i-1,"rank"] + 1)
}