[R] Cannot calculate mean() for double vector

Reuben Bellika rubenyi at gmail.com
Fri Oct 16 20:01:38 CEST 2009


OK. It looks like I just have several NA values at the start of my array:

> which (is.na(x_ema))
[1] 1 2 3 4 5 6 7 8 9

That make sense, because the moving average is not defined for those
positions. I'll just have to set those values to zero:

> x_ema = replace(x_ema, which(is.na(x_ema)), 0)
> which (is.na(x_ema))
integer(0)

The mean() call works now and I can get on with my work. I'll have to
remember to condition the data like this in the future.

Thanks for the help!

Reuben Bellika




More information about the R-help mailing list