# Moving window time series

I am working on some computations for large datasets of market data and I was wondering is there is a simple way to apply the following logic without using heavy looping. I will simplify the problem:

Say that I have a time series

data = 1 4 9 3.12 6.07 2 20.19 18.34 7.1 7.34 8.23 9.34 5.011

where each number represents a certain market value at each consecutive day (going from day 1 to day 13). I want to calculate a rolling standard deviation starting from day 9, that is, a new time series, where the first value is the standard deviation from values day 1 - day 9 in the data vector, second value is the standard deviation of day 2 - day 10 in the data vector ... until the standard deviation of day 5 - day 13 in the data vector and store these values in a new vector of length 5.

What is the easiest way to do this for large datasets? I have done some research and the package 'zoo' might be useful maybe? How to extend the above analysis when working with percentiles instead of standard deviations?

Thanks!

Functio rollapply in package zoo will let you apply a function (given as argument FUN) to a moving section of your time series. I think this is what you are after.