Вариант использования скользящего соединения в data.table
:
df1[df2, on=.(Time), roll="nearest", allow.cartesian=TRUE]
вывод:
Time Var1 Var2 Var3 Var4
1: 2019-01-01 01:10:00 A D C H
2: 2019-02-01 01:10:00 B E B I
3: 2019-02-01 10:10:00 B E G J
4: 2019-04-01 01:10:00 C F A K
данные:
library(data.table)
df1 <- fread('Time,Var1,Var2
01/01/2019 01:10:00,A,D
02/01/2019 01:10:00,B,E
03/01/2019 01:10:00,C,F')
df1[, Time := as.POSIXct(Time, format="%m/%d/%Y %T")]
df2 <- fread('Time,Var3,Var4
01/01/2019 01:10:00,C,H
02/01/2019 01:10:00,B,I
02/01/2019 10:10:00,G,J
04/01/2019 01:10:00,A,K')
df2[, Time := as.POSIXct(Time, format="%m/%d/%Y %T")]