[R] Cannot calculate mean() for double vector
Reuben Bellika
rubenyi at gmail.com
Fri Oct 16 19:06:39 CEST 2009
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
More information about the R-help
mailing list