Mean = NaN if NaN present [message #91766] |
Mon, 24 August 2015 16:56  |
laura.hike
Messages: 87 Registered: September 2013
|
Member |
|
|
Hi,
I (obviously) using data with NaNs filling in for bad data. I would like to take the mean of a subset of the data and have it fail (return NaN) if any NaNs are included in the subarray. If I use
a = mean(subarray, /NaN)
this only eliminates the NaNs from the computation, meaning that a mean would be returned even if there was only one good value in the subarray. Is there any way to do this besides incorporating an IF statement before the computation, such as
if (total(finite(subarray)) eq n_elements(subarray)) then a = mean(subarray) else a = !Values.F_NAN
which is not only convoluted but may be a nuisance to implement when indices are used to define the subarray?
Thanks,
Larry
|
|
|
|
|
Re: Mean = NaN if NaN present [message #91781 is a reply to message #91778] |
Tue, 25 August 2015 14:45  |
laura.hike
Messages: 87 Registered: September 2013
|
Member |
|
|
On Tuesday, August 25, 2015 at 7:08:41 AM UTC-7, Jeremy Bailin wrote:
>
> Don't you just want MEAN without the /NAN flag?
>
> -Jeremy.
Doh! I've been controlling for NaNs for too long! Thanks, Jeremy.
|
|
|