# from KTI SOW 2 NOV 2017
# written by Jacque Carlson
# create window counter: agg_index
n <- 10 # size of window
df1_agg_cc <- df1_cc %>%
group_by(dates) %>%
mutate(
dates_count = n(),
increment = rep(seq(1, n), length.out = dates_count)) %>%
group_by(
agg_index = cumsum(c(FALSE, diff(increment) < 0)) + 1 ) %>%
select(dates, agg_index, agg_vars) %>%
ungroup %>%
# create summarized cc vars -----------------------------------------------
group_by(dates, agg_index) %>%
summarise_all(funs(mean, sd)) %>%
ungroup