View source: R/rolling_percentile.R
rolling_percentile | R Documentation |
Function to calculate a rolling percentile from a vector.
rolling_percentile(
x,
width,
align = "center",
probs = 0.5,
na.rm = TRUE,
round = NA
)
x |
Numeric vector |
width |
Width of rolling window |
align |
Should the index of the result be center (default), left or right aligned compared to the rolling window of observations? |
probs |
Percentile to calculate |
na.rm |
Should NAs be removed before the percentile is computed? |
round |
Number of digits to round result to |
Numeric vector of same length as x
Shona Wilde
# define a vector - this is a daily time series
x <- c(41, 36, 12, 18, 28, 23, 19, 8, 7, 16, 11, 14, 18, 14, 34, 6, 30, 11)
# calculate rolling 7-day 99th percentile
rolling_percentile(
x,
width = 7,
probs = 0.99
)
# round to 1 decimal place only
rolling_percentile(
x,
width = 7,
probs = 0.99,
round = 1
)#'
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.