-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
826 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#' Lagged operations. | ||
#' | ||
#' @description | ||
#' Fast lags and leads | ||
#' | ||
#' @param x A vector. | ||
#' @param n Number of lags. Negative values are accepted. | ||
#' @param fill Value used to fill first n values. Default is `NA`. | ||
#' @param set Should x be updated by reference? If `TRUE` no copy is made and | ||
#' x is updated in place. The default is `FALSE`. | ||
#' @param recursive Should list elements be lagged as well? | ||
#' If `TRUE`, this is useful for data frames and will return row lags. | ||
#' If `FALSE` this will return a plain lagged list. | ||
#' | ||
#' @returns | ||
#' A lagged object the same size as x. | ||
#' | ||
#' @examples | ||
#' library(cheapr) | ||
#' library(bench) | ||
#' | ||
#' # A use-case for data.table | ||
#' | ||
#' df <- data.frame(x = 1:10^5) | ||
#' | ||
#' # Lag these behind by 3 rows | ||
#' lag_(df, 3, set = TRUE) | ||
#' | ||
#' sset(df, 1:5) # x variable was updated by reference! | ||
#' | ||
#' # The above can be used naturally in data.table to lag data | ||
#' # without any copies | ||
#' | ||
#' # To perform regular R row lags, just make sure set is `FALSE` | ||
#' | ||
#' sset(lag_(as.data.frame(EuStockMarkets), 5), 1:10) | ||
#' @export | ||
lag_ <- function(x, n = 1, fill = NULL, set = FALSE, recursive = TRUE){ | ||
.Call(`_cheapr_cpp_lag`, x, n, fill, set, recursive) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.