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
4 changes: 2 additions & 2 deletions R/hop-index.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#' hop_index(i, i, starts, stops, ~.x)
#'
#' # ---------------------------------------------------------------------------
#' # Non-existant dates with `lubridate::months()`
#' # Non-existent dates with `lubridate::months()`
#'
#' # Imagine you want to compute a 1 month rolling average on this
#' # irregular daily data.
Expand All @@ -81,7 +81,7 @@
#' )
#'
#' # This is because when you actually compute the `.i - .before` sequence,
#' # you hit non-existant dates. i.e. `"2019-03-29" - months(1)` doesn't exist.
#' # you hit non-existent dates. i.e. `"2019-03-29" - months(1)` doesn't exist.
#' i - months(1)
#'
#' # To get around this, lubridate provides `add_with_rollback()`,
Expand Down
2 changes: 1 addition & 1 deletion R/slide-index2.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Slide along multiples inputs simultaneously relative to an index
#' Slide along multiple inputs simultaneously relative to an index
#'
#' `slide_index2()` and `pslide_index()` represent the combination
#' of [slide2()] and [pslide()] with [slide_index()], allowing you to iterate
Expand Down
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
4 changes: 2 additions & 2 deletions man/hop_index.Rd

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

2 changes: 1 addition & 1 deletion man/slide_index2.Rd

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

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