Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用data.tables时循环_R_Data.table_Tidyverse - Fatal编程技术网

R 使用data.tables时循环

R 使用data.tables时循环,r,data.table,tidyverse,R,Data.table,Tidyverse,我有以下(代表性)数据集(实际数据集的一小部分) 换句话说,对于给定的(时间,模拟ID,N,折扣因子),对于x中的所有不同AgentID,分别在i中查找AgentIDs,其i\u阶段是AgentID的i\u反相(来自x) 当然,上述代码中的语法不起作用,因此我正在寻找实现上述操作的方法 注:纯数据。首选表解决方案。如果我正确理解了您的问题: a[a,.(x.AgentID,i.AgentID,Time,SimulationID,N,discountFactor,x.i_antiPhase), o

我有以下(代表性)数据集(实际数据集的一小部分)

换句话说,对于给定的
(时间,模拟ID,N,折扣因子)
,对于
x
中的所有不同
AgentID
,分别在
i
中查找
AgentID
s,其
i\u阶段
AgentID
i\u反相
(来自
x

当然,上述代码中的语法不起作用,因此我正在寻找实现上述操作的方法


注:纯
数据。首选表
解决方案。

如果我正确理解了您的问题:

a[a,.(x.AgentID,i.AgentID,Time,SimulationID,N,discountFactor,x.i_antiPhase), on=.(Time,SimulationID,N, i_phase=i_antiPhase),allow.cartesian=T][
   ,.(antiPhaseAgents=list(i.AgentID)),by=.(x.AgentID,Time,SimulationID,N,discountFactor)]

    x.AgentID Time SimulationID  N discountFactor       antiPhaseAgents
 1:         2    1            1 40              0  1, 4, 5, 7, 8,10,...
 2:         3    1            1 40              0  1, 4, 5, 7, 8,10,...
 3:         6    1            1 40              0  1, 4, 5, 7, 8,10,...
 4:         9    1            1 40              0  1, 4, 5, 7, 8,10,...
 5:        16    1            1 40              0  1, 4, 5, 7, 8,10,...
 6:        17    1            1 40              0  1, 4, 5, 7, 8,10,...

如果我正确理解了你的问题:

a[a,.(x.AgentID,i.AgentID,Time,SimulationID,N,discountFactor,x.i_antiPhase), on=.(Time,SimulationID,N, i_phase=i_antiPhase),allow.cartesian=T][
   ,.(antiPhaseAgents=list(i.AgentID)),by=.(x.AgentID,Time,SimulationID,N,discountFactor)]

    x.AgentID Time SimulationID  N discountFactor       antiPhaseAgents
 1:         2    1            1 40              0  1, 4, 5, 7, 8,10,...
 2:         3    1            1 40              0  1, 4, 5, 7, 8,10,...
 3:         6    1            1 40              0  1, 4, 5, 7, 8,10,...
 4:         9    1            1 40              0  1, 4, 5, 7, 8,10,...
 5:        16    1            1 40              0  1, 4, 5, 7, 8,10,...
 6:        17    1            1 40              0  1, 4, 5, 7, 8,10,...

代码末尾有一个空的
[]
是有原因的吗?原因是在最初的实现中,我使用了
:=
,正如您所做的那样,在这个引用赋值中
[]
允许显示结果。在最终的解决方案中不再需要它:我删除了它。代码末尾有空的
[]
有什么原因吗?原因是在最初的实现中,我使用了
:=
,正如您所做的那样,在这个引用赋值中
[]
允许显示结果。在最终的解决方案中不再需要这个:我删除了它。
a[a,.(x.AgentID,i.AgentID,Time,SimulationID,N,discountFactor,x.i_antiPhase), on=.(Time,SimulationID,N, i_phase=i_antiPhase),allow.cartesian=T][
   ,.(antiPhaseAgents=list(i.AgentID)),by=.(x.AgentID,Time,SimulationID,N,discountFactor)]

    x.AgentID Time SimulationID  N discountFactor       antiPhaseAgents
 1:         2    1            1 40              0  1, 4, 5, 7, 8,10,...
 2:         3    1            1 40              0  1, 4, 5, 7, 8,10,...
 3:         6    1            1 40              0  1, 4, 5, 7, 8,10,...
 4:         9    1            1 40              0  1, 4, 5, 7, 8,10,...
 5:        16    1            1 40              0  1, 4, 5, 7, 8,10,...
 6:        17    1            1 40              0  1, 4, 5, 7, 8,10,...