The zoo package is designed for use with (potentially irregular) time series data. It is widely used for any number of applications, but among its most frequently useful functions are the roll* functions, such as rollmean, rollmedian, rollmax, rollapply, etc.
Today’s Gist shows you how to use these rolling functions to summarize time series data across a moving window. That is, you can calculate any function on a 5-day (or second, or year) basis, across the length of the entire vector. This is certainly something that could be done with a simple loop, but the roll* functions make it easy and fast.