[R] help writing for loop
Jessica Schedlbauer
jschedlb at fiu.edu
Wed Nov 25 19:43:59 CET 2009
Hi,
I’d like to ask for some help in writing a loop. My situation is the following:
I have a matrix (matrix.A) containing 3 columns and 100 rows. The columns represent parameter estimates a, b, and c. The rows contain different values for these parameter estimates. Each row is unique.
I want to insert these parameter estimates into a model (say, y = a + bx + cx^2) and solve for y given a separate matrix (matrix.B) of x values (where x has a length of 1500).
I want to solve for y 100 times using each set of the parameter estimates in matrix.A once.
At present my code looks like this and it only performs the first iteration.
For (i in 1:length(matrix.A)) { y <- matrix.A$a[[i]] + matrixA$b[[i]] * matrix.B$x + matrixA$c[[i]] * matrix.B$x^2)
I have not been able to figure out how to loop through the rows of parameter estimates in matrix.A. I am new to writing loops, so any assistance would be much appreciated.
Regards,
Jessica Schedlbauer
More information about the R-help
mailing list