简体   繁体   中英

rollmin in R similar to zoo package rollmax

Is there a function for rollmin in the same way rollmean and rollmax work from the zoo package? I've looked into the zoo help document but can't find anything.

Run rollmax on the negative of the values and then negate the result. For example,

library(zoo)

 x <- 1:10

-rollmaxr(-x, 3, fill = NA)
## [1] NA NA  1  2  3  4  5  6  7  8

Another possibility is to use rollapply with the min function:

rollapplyr(x, 3, min, fill = NA)
## [1] NA NA  1  2  3  4  5  6  7  8

We can use roll_min from library(RcppRoll) the usage is

roll_min(x, n = 1L, weights = NULL, by = 1L, fill = numeric(0),
partial = FALSE, align = c("center", "left", "right"), normalize = TRUE, na.rm = FALSE)

eg

roll_min(1:10, 3, fill = NA, align = "right")
#[1] NA NA  1  2  3  4  5  6  7  8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM