根据距离和时间选择值

时间:2016-11-21 17:09:24

标签: r data.table

我想根据以下空间和时间条件匹配两个表的值:

  • 两小时的时间间隔
  • min(dist),max dist 20km

我可以使用for循环解决问题,但由于表格'尺寸为300万* 10,100 000 * 13,完成时间太长。

你有什么建议吗?我在下面张贴了一个实际例子和所需的outpu。谢谢。

示例

DT1 <- data.table(
Date = as.POSIXct(c("2005-01-05 10:40:00", "2005-01-06 10:40:00", "2005-01-07 10:40:00", "2005-01-08 10:40:00", "2005-01-09 10:40:00", "2005-01-10 10:40:00"), format = "%Y-%m-%d %T", tz = "GMT"), 
Lat = c(rep(50, 3), 35.44, 25.44, 15.44), 
Lon = c(rep(-50, 3), -10.44, -20.44, -30.44), 
Other.col = sample(LETTERS, 6))

DT2 <- data.table(
Date = as.POSIXct(c("2011-01-01 10:40:00", "2005-01-05 11:40:00", "2005-01-09 08:59:00", "2005-01-09 09:18:00", "2005-01-10 08:59:00"), format = "%Y-%m-%d %T", tz = "GMT"), 
Lat = c(35.44, 1, 25.54, 25.43, 15.46), 
Lon = c(-10.44, 1, -20.66, -20.42, -30.13),
Quality = c("h", "f", "n", "z", "l"))

DT1
                  Date   Lat    Lon Other.col
1: 2005-01-05 10:40:00 50.00 -50.00         E
2: 2005-01-06 10:40:00 50.00 -50.00         C
3: 2005-01-07 10:40:00 50.00 -50.00         O
4: 2005-01-08 10:40:00 35.44 -10.44         Z
5: 2005-01-09 10:40:00 25.44 -20.44         T
6: 2005-01-10 10:40:00 15.44 -30.44         S

DT2
                  Date   Lat    Lon Quality
1: 2011-01-01 10:40:00 35.44 -10.44       h
2: 2005-01-05 11:40:00  1.00   1.00       f
3: 2005-01-09 08:59:00 25.54 -20.66       n
4: 2005-01-09 09:18:00 25.43 -20.42       z
5: 2005-01-10 08:59:00 15.46 -30.13       l

Output
                  Date   Lat    Lon Other.col V2
1: 2005-01-05 10:40:00 50.00 -50.00         E NA
2: 2005-01-06 10:40:00 50.00 -50.00         C NA
3: 2005-01-07 10:40:00 50.00 -50.00         O NA
4: 2005-01-08 10:40:00 35.44 -10.44         Z NA
5: 2005-01-09 10:40:00 25.44 -20.44         T  z
6: 2005-01-10 10:40:00 15.44 -30.44         S  l

0 个答案:

没有答案