我有这个代码:
dat<-dat[,list(colA,colB
,RelativeIncome=Income/.SD[Nation=="America",Income]
,RelativeIncomeLog2=log2(Income)-log2(.SD[Nation=="America",Income])) #Read 1)
,by=list(Name,Nation)]
1) 我想说可以"RelativeIncomeLog2=log2(RelativeIncome)"
,但 "RelativeIncome"
不在j
's 范围内?
2)我尝试了以下方法(根据 data.table FAQ)。现在"RelativeIncome"
可用,但它不添加列:
dat<-dat[,{colA;colB;RelativeIncome=Income/.SD[Nation=="America",Income];
,RelativeIncomeLog2=log2(RelativeIncome)]))
,by=list(Name,Nation)]