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

Comments

@hadley
Copy link

hadley commented Sep 23, 2018

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

@jasonjfoster
Copy link
Owner

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

@jasonjfoster
Copy link
Owner

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 commented Jan 8, 2019

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants