我有817.741交易和12个变量一个买菜的数据集,看起来像这样:加快环data.table
Total_Input[,"Budget_Item"] <- FALSE
:
Date Customer_ID Age_Group Address Product_Subclass Product_ID Quantity Asset Price Price_Per_Unit Profit_Per_Item Budget_Item
1: 2000-11-01 00:00:00 46855 D E 110411 4.710085e+12 3 51 57 19 6 FALSE
2: 2000-11-01 00:00:00 539166 E E 130315 4.714981e+12 2 56 48 24 -8 TRUE
3: 2000-11-01 00:00:00 663373 F E 110217 4.710266e+12 1 180 135 135 -45 TRUE
我已经初始化变量“预算项目”
现在我想要预算项目为“真”(如果价格 - 资产< 0)。我通过一个for循环做到了这一点,但运行时间很长..任何建议如何做到这一点更多的时间&内存高效?
当前代码回路:
for(i in 1:nrow(Total_Input)){
if(Total_Input$Price[i] - Total_Input$Asset[i] <0){Total_Input$Budget_Item[i] = TRUE}
}
'Total_Input $ Budget_Item < - (Total_Input $价格 - Total_Input $资产)<0' – Axeman
@akrun,是我的数据集是data.table,确认。 – Rob