Minimum value. Smallest, tiniest, least.
Min()
is a math library function available in many programming environments which returns the entity of smallest value from two or more candidate values.
Do not use min for:
- Question about minimal value of type (
Long.MIN_VALUE
,Integer.MIN_VALUE
etc.)
Examples:
SQL
SQL MIN()
function is one of aggregate functions. It returns the smallest value of column.
Example:
SELECT MIN(column_name) FROM table_name;
Python
In Python
, the native min
function identifies the smallest element of a set (e.g., a list):
>> min([1, 2, 3])
1
Java
In Java we can use java.lang.Math
class to compute minimum value of two arguments. Example:
int minElement = Math.min(x, y);
To compute minimum element in collection we can use ,min()
method from java.util.Collections
class:
int minElement = Collections.min(list);
Ruby
In Ruby
to compute minimum element of collection we simply use min
function:
[4,7].min
Clojure
In Clojure
we use min
function in following way:
(min 1 2 3 4)
In above code `min' is function name and numbers 1..4 are arguments passed to it.
Or if we have list defined:
def myList [1 2 3 4]
then we can compute min this way:
(apply min myList)
R
In R we have function min
.
x <- c(1, 2, 3)
y <- c(4, 5)
z <- c(0, NA)
min(x)
min(y)
min(z)
min(z, na.rm = TRUE)
min(x, y, z, na.rm = TRUE) ## as same as min(c(x, y, z), na.rm = TRUE)