I have a dataframe of values (3 years in 10 minutes steps) and I want that if the barrier is higher than 900 that x gets NA for that time and that the previous 360 and following 360 values also get NA. x and barrier contain NAs.
- Time df$Time<- as.POSIXct(df$Time,format="%Y-%m-%d %H:%M",tz="GMT") [10 minute steps]
x my value what I want to be sorted out by the barrier
barrier if the barrier gets over 900 my x value should get NA That works with df$x <- ifelse(df$barrier > 900, NA, df$x) here you can see.
but I want that also the previous 6hours = 360 values should get NA as well as the following 6hours =360 values of x.
You can see on the picture that if the barrier (pink line) is over 900 the previous and following values are also affected (jumps), hence I want that the x values before and after get also NA .
My problem is I do not know how I can remove the previous and following values of x