cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

SOLVED
Newbie

## This Array Index is Invalid for This Array - NonMissingMean

Hi,

I'm trying to write a worksheet for some experiments that I carried out. Within the data sets are a number of NaNs, so I've put some code in to find the NonMissingMean, as I have to find the mean of different column vectors. The code is fine for NonMissingMean(D), where D is my data file, but when I try NonMissingMean(D^<2>) i.e. the mean of all data in column 2 that is a number, it says "this array index is not valid for this array".

I'm hoping someone here knows why this is, and possible ways of fixing it.

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: This Array Index is Invalid for This Array - NonMissingMean

we would need your data file to see where the problem occurs.

BTW it's rather confusing and unclear to spread the calculations over six pages width! At least I won't look at that kind of sheet in more detail.

Nevertheless I can image why your routine fails if the argument is just a one column vector: cols(M) returns 1. Your for-loop therefore runs down from 1 to zero and at first you try to access M_column<1> which does not exist --> error

Changing the rouitine to the following should solve the problem (additionally the first assignment assures that filterNaN() will not fail if no NaN is present in the vector/matrix):

3 REPLIES 3

## Re: This Array Index is Invalid for This Array - NonMissingMean

we would need your data file to see where the problem occurs.

BTW it's rather confusing and unclear to spread the calculations over six pages width! At least I won't look at that kind of sheet in more detail.

Nevertheless I can image why your routine fails if the argument is just a one column vector: cols(M) returns 1. Your for-loop therefore runs down from 1 to zero and at first you try to access M_column<1> which does not exist --> error

Changing the rouitine to the following should solve the problem (additionally the first assignment assures that filterNaN() will not fail if no NaN is present in the vector/matrix):

## Re: This Array Index is Invalid for This Array - NonMissingMean

Your program starts by defining newM <- M<0>.

Then you create a loop that stacks the other columns on top for i :=1 to cols(M)-1.

But if you send a single column vector there is no column 1, "this array index is not valid "for a single vector column array.

## Re: This Array Index is Invalid for This Array - NonMissingMean

Thanks for you reply Fred. I understand what you mean, but how can I modify either the loop to account for single vector column arrays, or change the manner in which I call for the NonMissingMean?

Thanks again

Announcements