【发布时间】:2015-11-14 19:09:00
【问题描述】:
如果我有一个矩阵,是否有一种方法可以对矩阵的行应用函数,从而对一定数量的行进行分组?
举个例子:我可能想对每百行中的十行使用矩阵上的 QR 分解来解决最小二乘问题。这可能看起来像:
set.seed(128)
f <- function(x) x^2 -x + 1
x <- runif(1000, -1, 1)
y <- f(x) + rnorm(1000, 0, 0.2)
morpheus <- cbind(1,x,x^2)
# apply qr.solve(morpheus, y) 100 times on 10 rows at a time
# in such way that the correspondence between morpheus and y is not broken
现在有人能解决这个问题吗?如果可能的话,我更喜欢使用任何形式的 apply 或其他功能解决方案的方法,但仍然欢迎任何帮助
【问题讨论】: