cummin()
cummin(x) Returns:
numeric · Updated March 13, 2026 · Base Functions cumulative vectors cummin base
The cummin() function computes the cumulative minimum of a vector, returning a vector of the same length where each element is the minimum of all preceding elements.
Syntax
cummin(x)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
x | numeric | required | A numeric vector |
Examples
Basic usage
x <- c(5, 4, 3, 2, 1)
cummin(x)
# [1] 5 4 3 2 1
# With increasing values
y <- c(1, 2, 3, 4, 5)
cummin(y)
# [1] 1 1 1 1 1
# With mixed values
z <- c(3, 1, 4, 1, 5)
cummin(z)
# [1] 3 1 1 1 1
Tracking running minimum
# Stock prices
prices <- c(100, 95, 105, 98, 110, 105, 115)
# Running minimum (lowest so far)
cummin(prices)
# [1] 100 95 95 95 95 95 95
Common Patterns
Drawdown tracking
# Portfolio values
portfolio <- c(10000, 9800, 10500, 9700, 10100, 9500, 10200)
# Maximum peak-to-trough decline
peak <- cummax(portfolio)
drawdown <- (portfolio - cummin(portfolio)) / peak
min(drawdown)
# [1] -0.1020408 # about 10% drawdown
Lowest temperature tracking
# Daily temperatures
temps <- c(72, 68, 75, 65, 70, 62, 71)
# Coldest day so far
cummin(temps)
# [1] 72 68 68 65 65 62 62