I have two unequally sized data frames called OBS and REF. Both contain 9864 columns - columns 1 and 2 are the longitude and latitude, and columns 3-9864 are daily temperature values for 27 years. They have vastly different numbers of rows - OBS has 12375 and REF has just 504.
OBS: 12375 obs. of 9864 variables
Lon Lat 1979.01.01 1979.01.02 1979.01.03
0.000 39.75 13.69 13.14 13.32
1.000 39.75 12.93 12.41 12.59
2.000 39.75 11.78 10.62 11.15
3.000 39.75 11.73 10.94 12.16
REF: 504 obs. of 9864 variables
Lon Lat 1979.01.01 1979.01.02 1979.01.03
0.0000 37.6559 12.69 12.35 12.60
2.8125 37.6559 13.43 12.97 13.23
5.6250 37.6559 13.91 13.64 13.71
8.4375 37.6559 14.12 14.24 14.01
What I want to do is output a new data frame (REF_Closest) that takes the coordinates from the OBS data frame, finds the closest coordinates from the REF data frame, and outputs these coordinates and all the variables to the right of this, e.g.:
REF_Closest: 12375 obs. of 9864 variables
Lon Lat 1979.01.01 1979.01.02 1979.01.03
0.0000 37.6559 12.69 12.35 12.60
0.0000 37.6559 12.69 12.35 12.60
2.8125 37.6559 13.43 12.97 13.23
2.8125 37.6559 13.43 12.97 13.23
I have tried adapting other similar questions but cannot work this out. Any suggestions?