Re: [R] Cannot calculate mean() for double vector

2009-10-16 Thread Reuben Bellika
It looks like I should read the documentation a bit more carefully. Simply ignoring the NA values when calculating the mean *is* a much better solution. (Although having 10 values out of a vector of 4 or so set to zero is *not* going to bias the mean toward zero in any significant way.) Thanks

Re: [R] Cannot calculate mean() for double vector

2009-10-16 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Reuben Bellika > Sent: Friday, October 16, 2009 11:02 AM > To: r-help@r-project.org > Subject: Re: [R] Cannot calculate mean() for double vector > >

Re: [R] Cannot calculate mean() for double vector

2009-10-16 Thread Sarah Goslee
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

Re: [R] Cannot calculate mean() for double vector

2009-10-16 Thread Ista Zahn
On Fri, Oct 16, 2009 at 2:01 PM, Reuben Bellika 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 val

Re: [R] Cannot calculate mean() for double vector

2009-10-16 Thread Reuben Bellika
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) > wh

Re: [R] Cannot calculate mean() for double vector

2009-10-16 Thread Alberto Monteiro
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. > > The

Re: [R] Cannot calculate mean() for double vector

2009-10-16 Thread Jason Rupert
using the error. Hope this helps at a bit. --- On Fri, 10/16/09, Reuben Bellika wrote: > From: Reuben Bellika > Subject: [R] Cannot calculate mean() for double vector > To: r-help@r-project.org > Date: Friday, October 16, 2009, 12:06 PM > I've been using R recently to ana

[R] Cannot calculate mean() for double vector

2009-10-16 Thread Reuben Bellika
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