I have a data set (sample) like below
Date Value 2019-05-01 0 2019-05-02 0 2019-05-03 0 2019-05-04 0 2019-05-05 0 2019-05-06 0 2019-05-07 0 2019-05-08 1 2019-05-09 0 I want to transform it such that, if I encounter Value=1, then I take the 3 values from 2 days before and fill it as 1. Also set the current value to be 0. In other words, the transformed data set should look like this
Date Value 2019-05-01 0 2019-05-02 0 2019-05-03 1 2019-05-04 1 2019-05-05 1 2019-05-06 0 2019-05-07 0 2019-05-08 0 2019-05-09 0 Do notice, that in the example above, 2019-05-08 was set to 0 after transformation, and 2019-05-03 to 2019-05-05 was set to 1 (last value set to 1 is 2 days before 2019-05-08 and 3 days preceding 2019-05-05 is also set to 1). If two consecutive values show up as 1, we start the date calculation from the last value that shows up as 1. I think I can do this via for loops, but was looking to see if any inbuilt functions can help me with this. Thanks!