我想加入两个data.table
,行数不同
Table 1= 18000 rows
Table 2= 3000 rows
要匹配两个表,有不同的条件 第一个条件:表2的ID应该与表1的ID相似 第二个条件:表2的日期应等于或大于表1的开始日期,且应小于表1的结束日期 我尝试了这样的代码,但没有用
match<-Table1[Table2, on = c("ID.currency==ID.currency", "start date<=date table2","end date>date table2")]
非常感谢您的帮助
表1: 结构(列表(ID.currency.startdate.open.high.low.close.volume.enddate.number.of.trades =结构(c(4L, 1L,2L,3L,5L),. Label = c(“ EURCHF,01/11/2017 01:00,1.1639,1.1656,1.1619,1.162,5500,01 / 11/2017 01:59,1555”, “ EURCHF,01/11/2017 02:00,1.1651,1.1666,1.1633,1.164,6000,01 / 11/2017 02:59,1900”, “ EURCHF,01/11/2017 03:00,1.1645,1.1662,1.1641,1.1657,6100,01 / 11/2017 03:59,3000”, “ EURUSD,01/11/2017 00:00,1.1619,1.1646,1.1659,1.1607,5000,01 / 11/2017 00:59,1500”, “ EURUSD,01/11/2017 04:00,1.1619,1.1646,1.1659,1.1607,7000,01 / 11/2017 04:59,3500” ),class =“ factor”)),row.names = c(NA,5L),class =“ data.frame”)
表2: structure(list(user.name.ID.currency.date.score = structure(c(2L, 3L,4L,1L,5L),.Label = c(“ Alpha,EURCHF,31/11/2017 00:57:00,2.98”, “ Alpha,EURUSD,2017/11/11 00:44,2.5”,“ Beta,EURCHF,2017/11/31 00:57:00,1.78”, “测试版,EURUSD,2017年1月11日04:12,3.23”,“测试版,欧元美元,2018年12月31日00:17,0.678” ),class =“ factor”)),row.names = c(NA,5L),class =“ data.frame”)
输出:
结构(list(ID(currency.startdate.open.high.low.close.volume.enddate.number.of.trades.user.name.ID.currency.date.score = structure(c(4L, 1L,2L,3L,5L),. Label = c(“ EURCHF,01/11/2017 01:00,1.1639,1.1656,1.1619,1.162,5500,01 / 11/2017 01:59,1555,NA,NA ,NA,NA“, “ EURCHF,01/11/2017 02:00,1.1651,1.1666,1.1633,1.164,6000,01 / 11/2017 02:59,1900,NA,NA,NA,NA”, “ EURCHF,01/11/2017 03:00,1.1645,1.1662,1.1641,1.1657,6100,01 / 11/2017 03:59,3000,NA,NA,NA,NA”, “ EURUSD,01/11/2017 00:00,1.1619,1.1646,1.1659,1.1607,5000,01 / 11/2017 00:59,1500,Alpha,EURUSD,01/11/2017 00:44,2.5”, “ EURUSD,01/11/2017 04:00,1.1619,1.1646,1.1659,1.1607,7000,01 / 11/2017 04:59,3500,Beta,EURUSD,01/11/2017 04:12,3.23” ),class =“ factor”)),row.names = c(NA,5L),class =“ data.frame”)
答案 0 :(得分:0)
这是我的sessionInfo的详细信息 sessionInfo() R版本3.5.2(2018-12-20) 平台:i386-w64-mingw32 / i386(32位) 运行于:Windows 7(内部版本7601)Service Pack 1