Are you sure that's the right solution? If you set them to 0, those values are averaged in with the others, and that could make a substantial difference.
A much better approach: mean(x_ema, na.rm=TRUE) - see the help for mean for more information. Sarah On Fri, Oct 16, 2009 at 2:01 PM, Reuben Bellika <rube...@gmail.com> wrote: > 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 > -- Sarah Goslee http://www.functionaldiversity.org ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.