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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

This Array Index is Invalid for This Array - NonMissingMean

ptc-5189599
1-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.

Thank you very much for your help in advance.

1 ACCEPTED SOLUTION

Accepted Solutions

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):

NonMissing.png

View solution in original post

3 REPLIES 3

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):

NonMissing.png

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.

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

Top Tags