If I have a matrix, does there exist a way to apply a function on the rows of a matrix in such way that a certain number of rows are grouped?
As an example: I might like to solve a least squares problem using QR decomposition on a matrix for every ten of my hundred rows. This might look like:
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
Would anybody now how this problem could be solved? If it would be possible, I'd prefer an approach using any form of apply or other functional solution, but still any help is welcome