I have two .csv files called 'tag.csv' and 'wind.csv' that I would like to merge based on the 'Date' column. However, as you can see from the data below the times do not match exactly.
tag.csv
Date
13/12/2014 05:11
13/12/2014 05:43
13/12/2014 06:34
wind.csv
Date
13/12/2014 05:00
13/12/2014 06:00
13/12/2014 07:00
I am using the following simple script.
tag<- read.csv("tag.csv")
wind<- read.csv("wind.csv")
myfulldata = merge(tag, wind)
Is there a command I could add so that the data will merge with the closest time? For example, 13/12/2014 05:11 will merge with 13/12/2014 05:00
data.tablepackage has its own merging method and an option calledrollthat allows closest matches. e.g.See Join R data.tables where key values are not exactly equal--combine rows with closest times for another example.
To be robust though, I would probably instead do some datetime manipulation to force them to both be to the nearest hour, and then do a nearest join if all else fails
edit: this method won't work on
data.frameobjects, if you haven't useddata.tablebefore maybe stay simple and round the hours