[R] Cannot calculate mean() for double vector

Jason Rupert jasonkrupert at yahoo.com
Fri Oct 16 19:35:38 CEST 2009


Have you tried:
mean(x)
mean(as.numeric(as.character(x)))
mean(x_ema)
mean(as.numeric(as.character(x_ema)))

What is the result of the following:
which(is.na(as.numeric(as.character(x_ema))))

Abit hard since you don't provide the data, but there may be an NA or character value that is causing the error.  

Hope this helps at a bit. 



--- On Fri, 10/16/09, Reuben Bellika <rubenyi at gmail.com> wrote:

> From: Reuben Bellika <rubenyi at gmail.com>
> Subject: [R] Cannot calculate mean() for double vector
> To: r-help at r-project.org
> Date: Friday, October 16, 2009, 12:06 PM
> 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. I can find the mean of the original
> integer data
> just fine, as well as for a simple test vector of 10
> doubles, but it
> never seems to return a usable result for the x_ema vector.
> Is this
> because the vector is too long? (Both x and x_ema contain
> around 40000
> values). Am I running into some memory limit? I can do
> other
> calculations with x_ema just fine, it's only the mean()
> function that
> doesn't seem to work. All the information in the help seems
> to
> indicate that this operation should work without a
> problem.
> 
> If it matters at all, I'm using R 2.9.2 running on Windows
> Vista.
> 
> I'd appreciate any help or suggestions as to what might be
> wrong.
> 
> Thank you,
> Reuben Bellika
> 
> ______________________________________________
> R-help at 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.
>




More information about the R-help mailing list