Minimum and maximum

Basic types / Numbers / Mathematical operations

min_value <- min(2, 1, 3)
# min_value = 1

nums <- c(2, 1, 3)
max_value <- max(nums)
# max_value = 3

# Both ends at once
bounds <- range(nums)
# bounds = 1 3

# Element with the most characters
words <- c("one", "three", "two")
longest <- words[which.max(nchar(words))]
# longest = three

# Empty input: -Inf (and a warning)
empty_max <- suppressWarnings(max(numeric(0)))
# empty_max = -Inf

cat("min_value =", min_value, "\n")
cat("max_value =", max_value, "\n")
cat("bounds =", bounds, "\n")
cat("longest =", longest, "\n")
cat("empty_max =", empty_max, "\n")