Say I have such a data.frame file
df <- data.frame(signal = c(0, 0, 1, 0, 1, 1, 0, 1, 1, 1))
What is the best way to find the first signal by the number that go sequentially n times. For example, if n = 1, then my signal will be the third element, and I would like to receive the answer as follows:
c(0, 0, 1, 0, 0, 0, 0, 0, 0, 0)
If n = 2, the answer will be:
c(0, 0, 0, 0, 0, 1, 0, 0, 0, 0)
And for n = 3, the last element is a signal after three lines in a row:
c(0, 0, 0, 0, 0, 0, 0, 0, 0, 1)