[R] 'subscript out of bounds' in matrices

Laura Gross laura at bayesian-bay.freeserve.co.uk
Mon Nov 12 10:22:18 CET 2001

Dear list

Having read through all the archives of the mailing lists, I've had no
luck finding the answer to my problem.

I am running a for(i in 1:n) loop and am creating a matrix, p, for each
of the n observations. This matrix p is a 2x1 matrix. I am then doing
the following:


to create a matrix with the elements of P on the diagonal (i.e. a 4x4

This works fine when I have n=60, however when I increase the size of
the data set to n=100, I get the error message:

Error in diag(c(p[1, 1], p[2, 1])) : subscript out of bounds

I put this down to a problem with memory at first so increased the
memory in my PC from 128Mb to 256Mb yet it made no difference and the
error still occurred. I am eventually going to need to run this command
for n=8000.

Could anybody suggest what I can do to solve this problem? Do I need to
store my matrix as another type of variable?

Thanks in advance for any help
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list