1
DB_envt
             datetime        STUDY_SITE  DATE_ENV GROUP_ENV TIME_ENV Depth Seastate SST Offshore Habitat Tide Behaviour
        1 2010-6-30 12:41:00   HongKong 30-Jun-10         1 12:41:00    NA        1  NA       NA      NS  Ebb      Rest
        2 2010-6-30 13:13:00   HongKong 30-Jun-10         1 13:13:00    NA        2  NA       NA      NS  Ebb      Rest
        3 2010-6-30 13:56:00   HongKong 30-Jun-10         2 13:56:00    NA        1  NA       NA      NS  Ebb      Rest
        4 2010-7-01 11:01:00   HongKong 01-Jul-10         1 11:01:00    NA        1  NA       30         High      Rest
        5 2010-7-01 11:38:00   HongKong 01-Jul-10         1 11:38:00    NA        1  NA       40         High      Rest
        6 2010-7-01 11:38:00   HongKong 01-Jul-10         2 11:38:00    NA        1  NA       40         High      Rest


DB_gps 
                datetime   PKey STUDY_SITE DATE_SIGHT GROUP_SIGHT         SPECIES TIME_SIGHT LATITUDE LONGITUDE
    1 2010-5-18 11:45:00 269253   HongKong  18-May-10           1 Sc   11:45:00 22.29043  113.8933
    2 2010-5-18 12:50:00 269254   HongKong  18-May-10           3 Sc   12:50:00 22.26373  113.8597
    3 2010-6-30 12:41:00 269241   HongKong  30-Jun-10           1 Sc   12:41:00 22.22835  113.8360
    4 2010-6-30 12:51:00 269242   HongKong  30-Jun-10           1 Sc   12:51:00 22.21963  113.8380
    5 2010-6-30 12:53:00 269243   HongKong  30-Jun-10           1 Sc   12:53:00 22.22932  113.8374
    6 2010-6-30 13:10:00 269244   HongKong  30-Jun-10           1 Sc   13:10:00 22.23020  113.8373

I have two dataframe, and I want to merge the nearest timepoint of DB_gps data to the DB_envt, lets say within 2 minutes range, and produce a NaN for that row of data if there's no GPS data within that +- 2 minutes range. How should I do in R?

Ho Yuen Wa
  • 57
  • 1
  • 3
  • 1
    Please use `dput` function to provide a [reproductible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example-aka-mcve-minimal-complete-and-ver) – Emmanuel-Lin Nov 30 '17 at 09:45

0 Answers0