Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4113486
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:19:51+00:00 2026-05-20T22:19:51+00:00

I have one file (location) that has an x,y coordinates and a date/time identification.

  • 0

I have one file (location) that has an x,y coordinates and a date/time identification. I want to get information from a second table (weather) that has a “similar” date/time variable and the co-variables (temperature and wind speed). The trick is the date/time are not exactly the same numbers in both tables. I want to select the weather data that is closest from the location data. I know I need to do some loops and thats about it.

Example location                                    example weather

x    y     date/time                         date/time           temp        wind
1    3     01/02/2003 18:00                  01/01/2003 13:00     12          15
2    3     01/02/2003 19:00                  01/02/2003 16:34     10          16
3    4     01/03/2003 23:00                  01/02/2003 20:55     14          22
2    5     01/04/2003 02:00                  01/02/2003 21:33     14          22
                                             01/03/2003 00:22     13          19
                                             01/03/2003 14:55     12          12
                                             01/03/2003 18:00     10          12
                                             01/03/2003 23:44     2           33
                                             01/04/2003 01:55     6           22

So the final output would be a table with the correctly “best” matched weather data to the location data

x    y     datetime               datetime           temp        wind
1    3     01/02/2003 18:00  ----  01/02/2003 16:34     10          16
2    3     01/02/2003 19:00  ----  01/02/2003 20:55     14          22
3    4     01/03/2003 23:00  ----  01/03/2003 00:22     13          19               
2    5     01/04/2003 02:00  ----  01/04/2003 01:55     6           22

Any suggestions where to start? I am trying to do this in R

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:19:52+00:00Added an answer on May 20, 2026 at 10:19 pm

    I needed to bring that data in as data and time separately and then paste and format

    location$dt.time <- as.POSIXct(paste(location$date, location$time), 
                                     format="%m/%d/%Y %H:%M")
    

    And the same for weather

    Then for each value of date.time in location, find the entry in weather that has the lowest absolute values for the time differences:

     sapply(location$dt.time, function(x) which.min(abs(difftime(x, weather$dt.time))))
    # [1] 2 3 8 9
     cbind(location, weather[ sapply(location$dt.time, 
                          function(x) which.min(abs(difftime(x, weather$dt.time)))), ])
    
      x y       date  time             dt.time       date  time temp wind             dt.time
    2 1 3 01/02/2003 18:00 2003-01-02 18:00:00 01/02/2003 16:34   10   16 2003-01-02 16:34:00
    3 2 3 01/02/2003 19:00 2003-01-02 19:00:00 01/02/2003 20:55   14   22 2003-01-02 20:55:00
    8 3 4 01/03/2003 23:00 2003-01-03 23:00:00 01/03/2003 23:44    2   33 2003-01-03 23:44:00
    9 2 5 01/04/2003 02:00 2003-01-04 02:00:00 01/04/2003 01:55    6   22 2003-01-04 01:55:00
    
     cbind(location, weather[ 
                      sapply(location$dt.time, 
                        function(x) which.min(abs(difftime(x, weather$dt.time)))), ])[ #pick columns
                              c(1,2,5,8,9,10)]
    
      x y             dt.time temp wind           dt.time.1
    2 1 3 2003-01-02 18:00:00   10   16 2003-01-02 16:34:00
    3 2 3 2003-01-02 19:00:00   14   22 2003-01-02 20:55:00
    8 3 4 2003-01-03 23:00:00    2   33 2003-01-03 23:44:00
    9 2 5 2003-01-04 02:00:00    6   22 2003-01-04 01:55:00
    

    My answers seem a bit different than yours but another reader has already questioned your abilities to do the matching properly by hand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a programmatically generated image that I want to send as an attachment
I have an ant task that contains javac task inside. It reports about error
I am trying to copy all files in one location to a different location
How does the Class-path in the MANIFEST.MF file determine the relative location? 1) Say
I have to make an iPhone app for a company which has a web
I have an abstract Catalog class as follows. It has a static method OpenCatalog()
Okay, here's the situation. I have two NSManagedObjects called Store and Aisle . There
I read John Robbins' article TFS 2010 Build Number and Assembly File Versions: Completely
I'm helping a veterinary clinic measuring pressure under a dogs paw. I use Python
I am using windbg with xp embedded. Attempting to fetch the operating system symbols

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.