我有两个数据帧和数据帧的dput在下面给出:搜索匹配两个数据帧
dput(DF1)
structure(list(observationtime = structure(c(0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
), format = "h:m:s", class = "times"), observationdate = structure(c(15309,
15309, 15309, 15309, 15309, 15309, 15309, 15309, 15309, 15309,
15309, 15309, 15309, 15309, 15309, 15309, 15309, 15309, 15309,
15309), class = "Date"), screentemperature = c(9.1, 9.4, 6.8,
5.7, 1.6, 6.3, 5.2, 4.7, 6.8, 8.7, 6.9, 9.6, 9.4, 9.5, 8.1, 7.7,
7.9, 8.9, 6.6, 6.8), significantweathercode = c(8L, 7L, 8L, 9L,
15L, 12L, 12L, 15L, 15L, 9L, 15L, 7L, 2L, 7L, 12L, 8L, 12L, 8L,
8L, 12L), latitude = c(60.139, 58.954, 57.358, 58.214, 57.725,
57.859, 57.257, 58.288, 56.867, 57.82, 57.206, 58.454, 57.6494,
57.712, 57.077, 56.85, 57.206, 57.698, 56.497, 55.681), longitude = c(-1.183,
-2.9, -7.397, -6.325, -4.896, -5.636, -5.809, -4.442, -4.708,
-3.97, -3.827, -3.089, -3.5606, -3.322, -2.836, -2.27, -2.202,
-2.121, -6.887, -6.256)), .Names = c("observationtime", "observationdate",
"screentemperature", "significantweathercode", "latitude", "longitude"
), row.names = c(1L, 3L, 4L, 5L, 6L, 7L, 8L, 10L, 11L, 12L, 13L,
14L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L), class = "data.frame")
dput(DF2)
structure(list(time = structure(c(0.0104166666666667, 0.0590277777777778
), format = "h:m:s", class = "times"), data = structure(c(15309,
15310), class = "Date"), latitude = c(53.674, 43.978), longitude = c(-1.222,
-5.346)), .Names = c("time", "data", "latitude", "longitude"), row.names = c(NA,
-2L), class = "data.frame")
我正在尝试使用df1的值从df2中提取温度和有意义的weathercode。例如,来自df2的日期将与df1的日期完全匹配,但时间可能不相同,因此我需要识别15-30分钟的阈值以找到最近的时间,并且同时我需要匹配坐标,因为它们可能不完全匹配,并且需要阈值才能找到最接近的匹配。步骤如下:
- 比赛日期
- 匹配的位置/ coordiantes,如果没有精确匹配,找到最接近
- 比赛的时候,如果没有精确匹配,找到最接近的时间
溶液我是
- 子集从DF1基于日期的数据
- 选择具有最小时间差的观察和最小距离
- 查找时间之间的差异,并协调
在现实中,数据是包含接近五十万行的每个数据帧的大。我试图找出一种有效的方法来尝试做这样的匹配。
建议将欢迎可能的解决方法。
很大程度上取决于您在每个数据框中具有多少独特位置。 – Thierry
在df1中有170个独特的位置,但在df1中有很多。我们正在谈论数千人。 – syebill