These functions behave similarly to min, max
and which(x == max/min (x)
to find the n-th greatest max or min of a dataset.
maxn(x,nth=1)
minn(x,nth=1)
which.maxn(x, nth = 1, arr.ind = FALSE, useNames = TRUE)
which.minn(x, nth = 1, arr.ind = FALSE, useNames = TRUE)
For maxn, minn
, a single value which is the nth- max or min.
For the which.min,max
functions, quoting from which
:
If arr.ind == FALSE (the default), an integer vector, or a double vector if x is a long vector, with length equal to sum(x), i.e., to the number of TRUEs in x.
If arr.ind == TRUE and x is an array (has a dim attribute), the result is arrayInd(which(x), dim(x), dimnames(x)), namely a matrix whose rows each are the indices of one element of x
A vector or array of numerical or string values. Note: ordering of string values may not be what is expected. See Details.
Which lesser(greater, for min functions) to find, with default nth==1 being identical to max, min
.
Same meaning as for which
, a logical value indicating whether to return the array indices if x
is an array.
Same meaning as for which
, a logical value indicating if the value of arrayInd() should have (non-null) dimnames at all
Carl Witthoft, carl@witthoft.com
Quoting the help page for max
:
Character versions are sorted lexicographically, and this depends on the collating sequence of the locale in use: the help for Comparison gives details. The max/min of an empty character vector is defined to be character NA. (One could argue that as "" is the smallest character element, the maximum should be "", but there is no obvious candidate for the minimum.)
set.seed(17) # for repeatability
foo <- matrix(sample(1:10,20,replace=TRUE),5,4)
maxn(foo,3)
which.minn(foo,4)
Run the code above in your browser using DataLab