Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
Re: Calculating mean (was mean and sdev)
In article <34FE5D52.70D510F8@linmpi.mpg.de> Kevin Ivory <Kevin.Ivory@linmpi.mpg.de> writes: > Kevin Spencer wrote: >> they get rid of stdev in the first place? And calculating the mean >> is trivial; just use total(x)/n_elements(x). > > It is not as trivial as that. If your array contains NaNs, you will > always get a NaN as a result. In many cases you will want to have > the mean of the finite values. I just looked at the source for moment in IDL 5.0.2, and it appears that it does not correctly handle NaNs. TypeX = SIZE(X) nX = TypeX[TypeX[0]+2] Mean = DATOTAL(X, Double = Double) / nX the function DATOTAL just calls total() and massages the return type. The documentation for total() says that you have to set /NAN to have it treat NaNs as missing data, and the call to total does not do that, nor does it remove the NaNs from the count of elements. scott -- Scott Stuart stuart at ll mit edu