Skip to content

Instantly share code, notes, and snippets.

@czeildi
Created June 11, 2017 11:16
Show Gist options
  • Save czeildi/6373809093cfc583ea0c909aef7e13c1 to your computer and use it in GitHub Desktop.
Save czeildi/6373809093cfc583ea0c909aef7e13c1 to your computer and use it in GitHub Desktop.
time series aggregation by different units in R using xts
library("xts")
dt <- data.table(
day = seq.Date(as.Date('2016-07-01'), by = 'day', length.out = 180),
x = 1:180,
y = 1001:1180
)
ts_data <- as.xts(dt)
monthly_sums <- apply.monthly(ts_data, apply, 2, sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment