rollingMax: Compute Rolling Max

View source: R/rollingMax.R

rollingMaxR Documentation

Compute Rolling Max

Description

The function computes the rolling maximum value along a time series.

Usage

rollingMax(mydata, length = 24)

Arguments

mydata

A numeric vector of data values

length

An integer specifying the window size (number of observations) to consider. Must be at least 3 (default = 24).

Details

It calculates the maximum over consecutive elements centered within a specified window.

For each index i, it considers a window of length points centered around i. When length is odd, the center falls exactly on i and the window extends equally to both sides. When length is even, the window extends one less point to the left than to the right and the rolling max is not exactly centered.

Values near the start of the series use windows with fewer than length data points if there are not enough preceding elements to form a full window. Similarly for values at the end.

Value

A numeric vector containing rolling maximum values, with same dimensions as mydata.

Examples

# Compute rolling max over a 24-hour period on hourly time series data
data(stMeteo)
ws_24h <- rollingMax(mydata = stMeteo$ws, length = 24)


simulariatools documentation built on Sept. 1, 2025, 5:09 p.m.