I want to calculate how long its been since something occurred.
Given the following, you can see that the light is on some of the time, but not all of the time. I wa
An approach using run length encoding (rle) and sequence (which is a wrapper for unlist(lapply(nvec, seq_len))
rle
sequence
unlist(lapply(nvec, seq_len))
d[, distance := sequence(rle(light)$lengths)][(light), distance := 0]