R: yes-no factor based on previous entries
R: yes-no factor based on previous entries I've got a timeseries dataset — data from meteostation. So there's 3 columns: time - time and date; p - rain, mm; h - water level,m. time p h I need to make a new column factor_rain , with 1 and 0 values. 1 - if water level( df$h ) was influenced by rain ( df$p ). This can be if there was a rain for the last 5 hours ( 5 entries ). In other cases, there should be 0 . factor_rain 1 0 1 df$h df$p 0 A part of dataset is here: df <- data.frame(time = c("2017-06-04 9:00:00", "2017-06-04 13:00:00", "2017-06-04 17:00:00", "2017-06-04 19:00:00", "2017-06-04 21:00:00", "2017-06-04 23:00:00", "2017-06-05 9:00:00", "2017-06-05 11:00:00", "2017-06-05 13:00:00", "2017-06-05 16:00:00", "2017-06-05 19:00:00", "2...