Reuben Bellika wrote:
>
> I've been using R recently to analyze some data, but I'm having a
> problem using the mean() function.
> 
> I imported the original data set as a vector of integers, x and then
> calculated a exponential moving average of the data, x_ema. This part
> worked fine.
> 
> Then, I tried to find the mean squared error between the original
> series and the moving average, using mse = mean((x - x_ema)^2). This
> gives N/A as a result, which seems to be the result of the mean
> function. When I run mean() on x_ema, which is of data type double,
>  it always returns N/A. 
>
So, x_ema includes one (or more) NA (and not N/A) in it.

Test: if (any(is.na(x_ema))) cat("Oops! NAs in x_ema\n")

If you want to get which of them are na: which(is.na(x_ema))

Alberto Monteiro

______________________________________________
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.

Reply via email to