【发布时间】:2017-04-20 14:42:42
【问题描述】:
我有这个代码:
getSomething = function(x, y) {
return something
}
b = matrix(NA, nrow = ncol(a), ncol = ncol(a))
# Loop through the columns
for(i in 1:ncol(a)) {
# Loop through the columns for each column
for(j in 1:ncol(a)) {
b[i, j] = getSomething(as.matrix(a[i]), as.matrix(a[j]))
}
}
它工作得很好,但是当我尝试在大数据集上运行代码时,它需要很长时间才能运行。
如何将其转换为lapply函数,使其运行更快?
谢谢。
【问题讨论】: