How to delete range of values before and after a value in a column based on a condition from another column in a DataFrame?

Hi everyone,

I have a data frame where one column, “Blink” indicates with 1 if blink was present during a recording and with 0 if it was not. My column “Value” stores the actual data I am using. I successfully filtered the column “Value” if “Blink” is equal to 1, thus, filtering values that happened during a blink.

I am also attempting to remove 12 values in the column “Value” before the first filtered value and 12 values after the last filtered value. Here is an example of what I am hoping for it to look like (if I wanted to filter 2 preceding and exceeding values):

I am unsure how to write a filter for the specific range before and after based on a condition from another column.

assume your data frame is df and you want to remove up to two elements before and to after (you can change 2 to 12 later):

julia> using DataFrames, ShiftedArrays

julia> df = DataFrame(blink = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0], id=1:10)
10×2 DataFrame
 Row │ blink  id
     │ Int64  Int64
─────┼──────────────
   1 │     1      1
   2 │     0      2
   3 │     0      3
   4 │     0      4
   5 │     0      5
   6 │     0      6
   7 │     1      7
   8 │     0      8
   9 │     0      9
  10 │     0     10

julia> subset(df, [:blink => x -> lag(x, i) .!== 1 for i in -2:2])
2×2 DataFrame
 Row │ blink  id
     │ Int64  Int64
─────┼──────────────
   1 │     0      4
   2 │     0     10