R365: Day 45 – {{xts}} applying functions daily/weekly/monthly

If you have time series data, you may want to reduce the data from hourly to daily/weekly/monthly data. Reasons to do this:

  • easy to summarize noisy data
  • see overall patterns across time
  • c’mon, it looks cooler
xts.ts <- xts(rnorm(231),as.Date(13514:13744,origin="1970-01-01"))
plot(xts.ts, main="Original Data")
plot((apply.weekly(xts.ts,mean)), main="Weekly Averages")
plot((apply.monthly(xts.ts,mean)), main="Monthly Averages")



The downside is that some of those peaks that seem really important when you zoom out to weekly or monthly data are not super noticeable at the daily level. It depends on what you want to do with the analysis.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s