Skip to content

moving average with gaps in time series

3 messages · Josef.Kardos at phila.gov, Jannis

#
Hi Josef,

is there any particular reason why you want to use your own function? 
Have a look at the stats functions or special timeseries functions for 
R. I am sure you will find something that calculates an ordinary moving 
average (and a bunch of fancier stuff).

'filter' (stats) for example can be used for moving averages. You could 
also use 'rollmean' from package zoo.

Not sure how to handle the missing values here, though (both ways most 
probably work with NAs). You could try 'rollaply 'from package zoo with 
a function that sums the valid values in the window and returns TRUE in 
case all are valid and FALSE if they are not. Not sure whether this is 
faster than your solution though.

Are you sure you want to compute a moving average with your missing 
values specification? Or do you just want to aggregate your values to 
hourly means, with those values removed where not all values are valid? 
(in that case 'aggregate' would be your function)


HTH
Jannis


Josef.Kardos at phila.gov schrieb:
3 days later