R API Reference

All functions accept a numeric vector x (and y for bivariate functions), a window_size integer, and an optional min_periods parameter compatible with pandas semantics.

rolling_cor(x, y, window_size, min_periods=window_size)

Rolling Correlation — Computes the rolling Pearson correlation between two numeric vectors.

Parameters:
  • x – A numeric vector of type double.

  • y – A numeric vector of type double, same length as x.

  • window_size – Positive integer window length.

  • min_periods – Minimum number of valid (non-NA) pairs required. Defaults to window_size.

Returns:

A numeric vector with rolling correlation values.

Example

x <- as.double(c(1, 2, 3, 4, 5))
y <- as.double(c(2, 4, 6, 8, 10))
rolling_cor(x, y, 3L)

rolling_cov(x, y, window_size, min_periods=window_size)

Rolling Covariance — Computes the rolling sample covariance (ddof=1) between two numeric vectors.

Parameters:
  • x – A numeric vector of type double.

  • y – A numeric vector of type double, same length as x.

  • window_size – Positive integer window length.

  • min_periods – Minimum number of valid (non-NA) pairs required. Defaults to window_size.

Returns:

A numeric vector with rolling covariance values.

Example

x <- as.double(c(1, 2, 3, 4, 5))
y <- as.double(c(2, 4, 6, 8, 10))
rolling_cov(x, y, 3L)

rolling_kurtosis(x, window_size, min_periods=window_size, method='stable')

Rolling Kurtosis — Computes the rolling excess kurtosis (Fisher) over a numeric vector. Requires at least 4 non-NA observations per window.

Parameters:
  • x – A numeric vector of type double.

  • window_size – Positive integer window length.

  • min_periods – Minimum number of non-NA observations required in a window to return a result. Defaults to window_size.

  • method"stable" (default) uses Terriberry’s online algorithm. "fast" uses a prefix-sum approach (faster, but susceptible to catastrophic cancellation when values are large and variance is small).

Returns:

A numeric vector with rolling excess kurtosis values.

Example

x <- as.double(c(1, 2, 3, 4, 5))
rolling_kurtosis(x, 4L)

rolling_max(x, window_size, min_periods=window_size)

Rolling Maximum — Computes the rolling maximum over a numeric vector using a monotonic deque.

Parameters:
  • x – A numeric vector of type double.

  • window_size – Positive integer window length.

  • min_periods – Minimum number of non-NA observations required in a window to return a result. Defaults to window_size.

Returns:

A numeric vector with rolling maximum values.

Example

x <- as.double(c(1, 3, 2, 5, 4))
rolling_max(x, 3L)

rolling_mean(x, window_size, min_periods=window_size, assume_finite=FALSE)

Rolling Mean — Computes the rolling mean over a numeric vector.

Parameters:
  • x – A numeric vector of type double.

  • window_size – Positive integer window length.

  • min_periods – Minimum number of non-NA observations required in a window to return a result. Defaults to window_size.

  • assume_finite – If TRUE, assumes the input contains no NA values and uses a faster SIMD prefix-sum path. Passing TRUE when NA``s are present produces incorrect results. Defaults to ``FALSE.

Returns:

A numeric vector with rolling mean values.

Example

x <- as.double(c(1, 2, 3, 4))
rolling_mean(x, 3L)

rolling_median(x, window_size, min_periods=window_size, expect_nan=FALSE)

Rolling Median — Computes the rolling median over a numeric vector. Automatically selects the fastest algorithm based on window size and expected NaN density: FlatMedian (sorted vector) for small windows, MultisetMedian (red-black tree) for medium windows, or TwoHeapMedian (lazy-deletion heaps) for large windows or NaN-heavy data.

Parameters:
  • x – A numeric vector of type double.

  • window_size – Positive integer window length.

  • min_periods – Minimum number of non-NA observations required in a window to return a result. Defaults to window_size.

  • expect_nan – Logical. If TRUE, hints that the input may contain many NA values; switches dispatch thresholds to NaN-robust paths (avoids MultisetMedian’s iterator-shift degradation). Defaults to FALSE.

Returns:

A numeric vector with rolling median values.

Example

x <- as.double(c(1, 3, 2, 5, 4))
rolling_median(x, 3L)

rolling_min(x, window_size, min_periods=window_size)

Rolling Minimum — Computes the rolling minimum over a numeric vector using a monotonic deque.

Parameters:
  • x – A numeric vector of type double.

  • window_size – Positive integer window length.

  • min_periods – Minimum number of non-NA observations required in a window to return a result. Defaults to window_size.

Returns:

A numeric vector with rolling minimum values.

Example

x <- as.double(c(1, 3, 2, 5, 4))
rolling_min(x, 3L)

rolling_skewness(x, window_size, min_periods=window_size, method='stable')

Rolling Skewness — Computes the rolling adjusted Fisher-Pearson skewness over a numeric vector. Requires at least 3 non-NA observations per window.

Parameters:
  • x – A numeric vector of type double.

  • window_size – Positive integer window length.

  • min_periods – Minimum number of non-NA observations required in a window to return a result. Defaults to window_size.

  • method"stable" (default) uses Terriberry’s online algorithm. "fast" uses a prefix-sum approach (faster, but susceptible to catastrophic cancellation when values are large and variance is small).

Returns:

A numeric vector with rolling skewness values.

Example

x <- as.double(c(1, 2, 3, 4, 5))
rolling_skewness(x, 3L)

rolling_variance(x, window_size, min_periods=window_size, method='stable')

Rolling Sample Variance — Computes the rolling sample variance over a numeric vector.

Parameters:
  • x – A numeric vector of type double.

  • window_size – Positive integer window length.

  • min_periods – Minimum number of non-NA observations required in a window to return a result. Defaults to window_size (pandas semantics). Positions with fewer non-NA values yield NA.

  • method"stable" (default) uses the Welford online algorithm. "fast" uses a prefix-sum approach (faster, but susceptible to catastrophic cancellation when values are large and variance is small).

Returns:

A numeric vector with rolling sample variance values. Entries are NA when fewer than min_periods non-NA observations are present in the window, and NaN when variance is undefined (fewer than two values).

Example

x <- as.double(c(1, 2, 3, 4))
rolling_variance(x, 3L)