当两个数据帧具有不同的时间时,如何按时间合并它们

时间:2019-11-20 20:27:43

标签: database time merge range conditional-statements

请给我一些帮助。我需要在TIME之前合并两个数据库,但是我不知道如何做。

数据库1(两栖动物)每5秒观察一次。


DATE    TIME    CDOM    Chl LAT LONG
9/13/2019   9:00:01 AM  81.6    16.39   29.908773   -90.272686
9/13/2019   9:00:06 AM  81.56   16.31   29.908773   -90.272686
9/13/2019   9:00:11 AM  81.5    16.19   29.908772   -90.272686
9/13/2019   9:00:16 AM  81.4    16.62   29.908772   -90.272686
9/13/2019   9:00:21 AM  81.45   16.88   29.908772   -90.272686
9/13/2019   9:04:51 AM  81.18   17.37   29.908586   -90.272663
9/13/2019   9:04:56 AM  81.22   17.57   29.90856    -90.272673
9/13/2019   9:05:01 AM  81.25   17.6    29.908522   -90.272668
9/13/2019   9:05:06 AM  81.28   17.66   29.908482   -90.272647
9/13/2019   9:05:11 AM  81.11   17.39   29.908434   -90.272621
9/13/2019   9:05:16 AM  81.13   17.08   29.90838    -90.272595
9/13/2019   9:05:21 AM  80.95   16.99   29.908323   -90.272568
9/13/2019   9:05:26 AM  80.93   17.5    29.908265   -90.27254
9/13/2019   9:05:31 AM  80.81   17.1    29.908209   -90.272523
9/13/2019   9:05:36 AM  80.84   17.29   29.908152   -90.272504
9/13/2019   9:05:41 AM  80.85   17.85   29.908089   -90.272491
9/13/2019   9:05:46 AM  80.84   17.41   29.908029   -90.272485
9/13/2019   9:05:51 AM  80.96   18.21   29.907968   -90.272471
9/13/2019   9:05:56 AM  80.83   17.88   29.907914   -90.272442

数据库2每隔10秒由观察组成。

DATE    TIME    pCO2
9/13/2019   8:59:57 AM  851.45
9/13/2019   9:00:09 AM  854.42
9/13/2019   9:00:20 AM  856.61
9/13/2019   9:04:56 AM  931.6
9/13/2019   9:05:07 AM  935.23
9/13/2019   9:05:18 AM  940.03
9/13/2019   9:05:29 AM  942.46
9/13/2019   9:05:40 AM  947.5
9/13/2019   9:05:51 AM  949.54

我想合并两个数据库,将pCO2的值与两栖动物中具有相同TIME的列相匹配,但是对于那些不匹配的pCO2 TIMES,我想将它们与两栖动物中的值相匹配。两栖数据库#1前5秒的范围。

预期结果:

DATE    TIME    CDOM    Chl LAT LONG    pCO2
9/13/2019   9:00:01 AM  81.6    16.39   29.908773   -90.272686  NA
9/13/2019   9:00:06 AM  81.56   16.31   29.908773   -90.272686  854.42
9/13/2019   9:00:11 AM  81.5    16.19   29.908772   -90.272686  NA
9/13/2019   9:00:16 AM  81.4    16.62   29.908772   -90.272686  856.61
9/13/2019   9:00:21 AM  81.45   16.88   29.908772   -90.272686  NA
9/13/2019   9:04:51 AM  81.18   17.37   29.908586   -90.272663  NA
9/13/2019   9:04:56 AM  81.22   17.57   29.90856    -90.272673  931.6
9/13/2019   9:05:01 AM  81.25   17.6    29.908522   -90.272668  NA
9/13/2019   9:05:06 AM  81.28   17.66   29.908482   -90.272647  935.23
9/13/2019   9:05:11 AM  81.11   17.39   29.908434   -90.272621  NA
9/13/2019   9:05:16 AM  81.13   17.08   29.90838    -90.272595  940.03
9/13/2019   9:05:21 AM  80.95   16.99   29.908323   -90.272568  NA
9/13/2019   9:05:26 AM  80.93   17.5    29.908265   -90.27254   942.46
9/13/2019   9:05:31 AM  80.81   17.1    29.908209   -90.272523  NA
9/13/2019   9:05:36 AM  80.84   17.29   29.908152   -90.272504  947.5
9/13/2019   9:05:41 AM  80.85   17.85   29.908089   -90.272491  NA
9/13/2019   9:05:46 AM  80.84   17.41   29.908029   -90.272485  NA
9/13/2019   9:05:51 AM  80.96   18.21   29.907968   -90.272471  949.54
9/13/2019   9:05:56 AM  80.83   17.88   29.907914   -90.272442  NA

我能够合并它们,但是我不知道如何合并它们,包括所需的范围/间隔。 在此先感谢!

0 个答案:

没有答案