tmp <- dt[,list(par1=par1[which.max(perf)],par2=par2[which.max(perf)], perf=max(perf)), by=list(ticker,row_names)]res <- tmp[,list(perf=mean(perf),par1= paste(par1,collapse=","), par2=paste(par2,collapse=",")),by=row_names]使用 data.table 可使我按组和股票行情组合计算最大性能.然后,执行此操作后,我可以按 row_names 进行分组.并得到相同的结果!Using data.table allows me to calculate the max perf by group and ticker combinations. Then after doing that, I can group by row_names. And it gets the same results!> res row_names perf par1 par21: M 0.010413549 2,2 2,12: N 0.009508122 2,2 1,13: O 0.009314068 1,1 2,14: P 0.008883106 2,1 2,25: Q 0.009316006 2,2 2,2 这篇关于如何遍历列的所有组合并在R中按组应用功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-25 14:47