Skip to main content
16-Pearl
September 29, 2016
Solved

Avoid filterNaN error if there is no NaN

  • September 29, 2016
  • 10 replies
  • 3679 views

I have various data sets I'm performing some analysis on. Sometimes they have blanks, sometimes not.  I can easily filter out the blanks with filterNaN.  The problem is if there are no blanks the filterNaN errors out.  So, I have to rewrite the statements for each column as to whether I need to filter or not.  I'd like one command that works whether I have blanks or not. What are my options?  Here's a simple example:

filter.jpg

Here, I want to return B = [1 2 3 4 5]^T

Prime 3.1 (and is this a bug?)

Thanks,

Best answer by MJG

Write a short program with "try..on error"

10 replies

24-Ruby IV
September 29, 2016

MJG1-VisitorAnswer
1-Visitor
September 29, 2016

Write a short program with "try..on error"

23-Emerald I
October 3, 2016

That's a very elegant solution.

But what if the data is paired--the rows are time sequential for example.  The solution presented does not maintain that pairing; the resulting vectors are different lengths.

The attached (much less elegant) program will maintain the row correlation of a data set while stripping out any rows with missing data.

DJF16-PearlAuthor
16-Pearl
October 3, 2016

Excellent work as always Fred.  My immediate problem did not require keeping data aligned in rows, as I was just making histograms and didn't want to eliminate rows needlessly.  However, I was toying with the idea that I'd need your solution going forward since each row of data actually aligns with a test unit.  So, I'll definitely be saving this one.  Thanks!