I have 2 tables (data1 and data2). My goal is to keep data in data2 that matches with "Site" and "Date" in data1 and also is within +/- 1 hour of data1. I have an example of what I am looking for below:
data1 <- data.frame("Site" = c("ABC", "ABC", "ABC", "EFG", "EFG", "EFG", "EFG"),
"Date" = c("2022-02-02", "2022-02-02", "2022-02-05", "2011-01-01", "2011-01-01",
"2012-01-03", "2012-01-05"),"Time" = c("12:00", "13:00", "15:00", "20:00", "20:30",
"21:59", "23:00"))
data2 <- data.frame("Site" = c("ABC", "ABC", "ABC", "EFG", "EFG", "EFG"), "Date" =
c("2022-02-02", "2022-02-02", "2022-02-05", "2011-01-01", "2011-01-01", "2012-01-05"),"Time" = c("12:00", "14:30", "16:00", "20:00", "23:00", "22:00"))
data_final <- data.frame("Site" = c("ABC", "ABC", "EFG", "EFG"), "Date" = c("2022-02-02", "2022-02-05", "2011-01-01", "2022-01-05"), "Time" = c("12:00", "16:00", "20:00",
"22:00"))
data_final is what I would like to end with. data1 has more rows than data2 does. I want to filter data2 to keep data that is within +/- 1 hour matching with date and site. Thank you for your help and let me know if you have any questions :)