我想找到一堆列的累积总和,如R: ddply repeats yearly accumulate data中所述。那是,
ddply(mydf, "year", transform,
cumsum1 = cumsum(myvalue1),
cumsum2 = cumsum(myvalue2))
我尝试了以下。
解决方案1:
1.创建了累积和的目的地名称列表和源名称列表。
2.跑ddply(mydf,"year",transform,dstnList=srcList)
3.得到以下错误:
"arguments imply differing number of rows: 1385, 280
In addition: Warning message:
In eval(expr, envir, enclos) : NAs introduced by coercion"
解决方案 2:
1.创建以下函数。
findCumSum<-function(srcdf,columnlist){
for (i in 1:length(columnlist)){
ddply(srcdf,"g_id",transform,cumsum(names(srcdf)[columnlist[i]]))
}
srcdf
}
2.调用带有srcList列表的函数。findCumSum(mydf,srcIdxList)
;
我收到以下错误
"Error in eval(expr, envir, enclos) : object 'srcdf' not found"
让我知道如何解决问题。