Subscribe Bookmark RSS Feed

List of Missing Values

aallman

Occasional Contributor

Joined:

Feb 28, 2017

I am writing a script that determines positional information using lists. It repeats several times for different groups of data, but some of the groups do not contain what I am looking for. This results in a list of missing values {., ., ., ., ., .}. 

 

When there are values in the list, I use List[Loc Nonmissing(List)] to get only the nonmissing values from my list and then N Items to count how many nonmissing values my list contains. However, when the list has only empty values, Loc Nonmissing returns [](0,1) which gives an error because it is used as a subscript. 

 

I can't figure out a way to deal with these lists full of missing values. Does anyone have any ideas???

3 REPLIES
M_Anderson

Staff

Joined:

Nov 21, 2014

Maybe try using a "Try()".  This will prevent the error and you can add an argument in the Try() statement to just assign a value of zero to any variable that might contain the N Items command.  

 

 

txnelson

Super User

Joined:

Jun 22, 2012

Another method that I have used in such cases, is to use the Sum() function.  It will work for both lists and scaler values, and will return a missing value when all elements of the list are missing.

Jim
Jeff_Perkinson

Community Manager

Joined:

Jun 23, 2011

The [](0,1) indicates that it returned a matrix with 0 rows and 1 column.

 

So, you can use the NRow() function to see if it has 0 rows and act accordingly.

 

//:*/
x={., ., ., ., ., .};

y=loc nonmissing(x);

nrow(y);
/*:

0
-Jeff