min

Basics

min is a simple function which returns the minimum value in a vector or column in a data.frame. This can be used to compare the minimum values between columns, find the minimum value of a row, or find a string that’s alphabetically first in a list.


Examples

What is the smallest value in the vector weights?

Click to see solution
weights <- c(147, 280, 180, 190, 145)
min(weights)
[1] 145

What is the smallest response over an experiment data.frame with trial1, trial2, and trial3 as its trial columns?

Click to see solution
min(c(experiment$trial1, experiment$trial2, experiment$trial3))
[1] 87

How do I get the minimum of the values in a vector when some of the values are: NA, NaN?

Click to see solution

See our mean page for information on na.rm.

vec <- c(NA, 45, 444, 13, 98, NA)
min(vec, na.rm = TRUE)
[1] 13

What is the first word in alphabetical order in the vector sentence?

Click to see solution
sentence <- c('I', 'thought', 'red', 'would', 'have', 'felt', 'warmer', 'in', 'the', 'summer')
min(sentence)
[1] "felt"