Skip to content
Prev 141719 / 398498 Next

Arrays and functions

On 13-Apr-08 08:43:33, Louisa Hay wrote:
You have created a 3-dimensional array 'res' with
dimensions 2x2x3.

Apart from anything else, when you make the assignment

  res[distribution,test,samplesize]<-results

the first value of 'samplesize' you use will be 10.
There is no array element with 3rd index equal to 10
(the maximum possible is 3). Hence (I suspect) your
error message.

I would recommend re-writing your code so that you use
the numbers of elements in each of your vectors
'distributions', 'tests' and 'samplesizes' to set the
ranges in your 'for' loops.

For example:

  Ndist<-length(distributions)
  Ntest<-length(tests)
  Nsamp<-length(samplesizes)

and then you can do, for instance,

  for(idist in (1:Ndist)){
   for(itest in (1:Ntest)){
    for(isamp in (1:Nsamp)){
     for(i in (1:k)){
      results<-size()
      res[idist,itest,isamp]<-results
     }
    }
   }
  }

I also suspect that there are a lot of other things in
your code which could do with looking at too, but at
least the above approach should get you past the "subscript
out of bounds" problem!

Best wishes,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 13-Apr-08                                       Time: 10:23:11
------------------------------ XFMail ------------------------------