I was also thinking of rle
and seq_len
:
df$No_Days <- unlist(sapply(rle(df$Runoff)$lengths,
function(x)
if (x>1)
rev(seq_len(x))
else 0))