You can join df1
and df2
by Machine.No
, convert the columns to POSIXct
format and keep only rows which are outside of Start.Time
and End.Time
.
library(dplyr)
df1 %>%
inner_join(df2, by = 'Machine.No') %>%
mutate(across(c(Start.Time, End.Time,timestamp), lubridate::dmy_hm)) %>%
filter(!(timestamp >= Start.Time & timestamp <= End.Time))
Or in base R :
res <- merge(df1, df2, by = 'Machine.No')
res[2:4] <- lapply(res[2:4], as.POSIXct, format = '%d-%m-%Y %H:%M', tz = 'UTC')
subset(res, !(timestamp >= Start.Time & timestamp <= End.Time))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…