Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions R/summary-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@
#'
#' # Only evaluate the sum on windows that have the potential to be complete
#' slide_index_sum(x, i, before = 2, after = 1, complete = TRUE)
#'
#' # ---------------------------------------------------------------------------
#' # Panel data (grouped rolling operations)
#'
#' # In Stata, the equivalent of grouped rolling means is:
#' # rangestat (mean) roll_mean = sales, int(date -2 0) by(firm)
#'
#' # slider + dplyr replicates this pattern with group_by():
#' df <- data.frame(
#' firm = rep(c("A", "B"), each = 4),
#' date = as.Date(c(
#' "2020-01-01", "2020-01-02", "2020-01-05", "2020-01-06",
#' "2020-01-01", "2020-01-03", "2020-01-04", "2020-01-07"
#' )),
#' sales = c(10, 12, 15, 13, 20, 22, 18, 25)
#' )
#'
#' # 3-day rolling mean within each firm, respecting irregular date gaps
#' df$roll_mean <- unlist(
#' lapply(split(df, df$firm), function(g) {
#' slide_index_mean(g$sales, g$date, before = 2)
#' })
#' )
#' df
slide_index_sum <- function(
x,
i,
Expand Down
24 changes: 24 additions & 0 deletions man/summary-index.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading