I have a dataset with start and end times for events (called df_time), and another dataset with when an event happened (df_val). I want to use df_time to filter down df_val only to events that happened within recorded time intervals.
I'm a bit lost on how to accomplish this though.
start = c(1, 5, 7, 4) end = c(2, 7, 11, 7) df_time = data.frame(start, end) time = c(3, 6, 2, 10, 11) val = c(100, 20, 30, 40, 50) df_val = data.frame(time, val) df_val %>% select_all() %>% filter(time >= df_time$start & time <= df_time$end) Output:
time val 1 6 20 Warning messages: 1: In time >= df_time$start : longer object length is not a multiple of shorter object length 2: In time <= df_time$end : longer object length is not a multiple of shorter object length The above will run with warning messages (above), and gives me the wrong output (ignores starts/ends that are equal to value timestamps). Above, all values but 3 should be printed.
I'm unsure on how to fix this, and would appreciate any help/resources!