Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roll_min and roll_max #13

Closed
hadley opened this issue Sep 23, 2018 · 3 comments
Closed

roll_min and roll_max #13

hadley opened this issue Sep 23, 2018 · 3 comments
Labels

Comments

@hadley
Copy link

@hadley hadley commented Sep 23, 2018

Would you consider implementing rolling versions of min() and max()

@jjf234
Copy link
Owner

@jjf234 jjf234 commented Sep 25, 2018

Thanks, I would also like to include in future versions (see #4).

@jjf234 jjf234 added the enhancement label Sep 26, 2018
@jjf234 jjf234 mentioned this issue Oct 20, 2018
@jjf234
Copy link
Owner

@jjf234 jjf234 commented Jan 8, 2019

I have added both roll_min and roll_max in the development version. Here's an example:

# devtools::install_github("jjf234/roll")

library(roll)
library(testthat)

n_vars <- 30
n_obs <- 1500
x <- matrix(rnorm(n_obs * n_vars), nrow = n_obs, ncol = n_vars)

# rolling minimums ('min_obs = 1' equivalent to 'partial = TRUE')
expect_equivalent(roll_min(x, 5, min_obs = 1),
                  rollapplyr(x, 5, min, partial = TRUE))

# rolling maximums
expect_equivalent(roll_max(x, 5, min_obs = 1),
                  rollapplyr(x, 5, max, partial = TRUE))
@hadley
Copy link
Author

@hadley hadley commented Jan 8, 2019

Awesome, thanks!

@jjf234 jjf234 closed this Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.