更新时间:2023-08-28 16:59:10
忽略代码段,并坚持要在列号 j j 的初始规范. /em>,然后对结果求和" ...您可以这样做:
Ignoring your code snippet and sticking to your initial specification that you want to apply function j on the column number j and then "sum the results"... you can do:
mapply( do.call, funs, lapply( mydata, list))
# [,1] [,2] [,3] [,4]
# [1,] 1 27 0.8414710 2
# [2,] 4 8 0.9092974 3
# [3,] 9 1 0.9092974 3
我不确定现在要以哪种方式添加结果(即按行或按列),因此可以在此矩阵上执行rowSums
或colSums
.例如:
I wasn't sure which way you want to now add the results (i.e. row-wise or column-wise), so you could either do rowSums
or colSums
on this matrix. E.g:
colSums( mapply( do.call, funs, lapply( mydata, list)) )
# [1] 14.000000 36.000000 2.660066 8.000000