Re: [R] Moving Average Non Uniform Vectors

2014-03-28 Thread Luca Cerone
Thanks Jim, this partially helps (I wasn't aware of the functions you used, which are good to know). I have two main doubts about your solution though. First of all, in my application x is large ~25 elements and I have to repeat this for ~1000 different y vectors; moreover the range of x is

Re: [R] Moving Average Non Uniform Vectors

2014-03-28 Thread jim holtman
If you don't need a 'running average', there are other 'smoothers' you can look at. Try 'supsmu': set.seed(1) x = c(0,1, 3,3.4, 5, 10, 11.23) y = x**2 + rnorm(length(x)) rbind(x, y) [,1] [,2] [,3] [,4] [,5] [,6] [,7] x 0.000 1.00 3.00 3.4

[R] Moving Average Non Uniform Vectors

2014-03-27 Thread Luca Cerone
Dear all, I have a vector x and a vector y = f(x). e.g. x = c(0,1, 3,3.4, 5, 10, 11.23) y = x**2 + rnorm(length(x)) I would like to apply a moving average to y, knowing that the x values are not uniformly spaced. How can I do this in R? What alternatives I have to filter out the noise from Y??

Re: [R] Moving Average Non Uniform Vectors

2014-03-27 Thread jim holtman
Here is one way. I took your data and applied the 'approx' function to get evenly spaced values and then 'filter' to create a moving average of a window of size 5. set.seed(1) x = c(0,1, 3,3.4, 5, 10, 11.23) y = x**2 + rnorm(length(x)) rbind(x, y) # create 'even' spacing using the 'approx'