Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

Extremes: Maxima and Minima

ExtremesR Documentation

Maxima and Minima

Description

Returns the (regular orparallel) maxima and minima of theinput values.

pmax*() andpmin*() take one or more vectors asarguments, recycle them to common length and return a single vectorgiving the‘parallel’ maxima (or minima) of the argumentvectors.

Usage

max(..., na.rm = FALSE)min(..., na.rm = FALSE)pmax(..., na.rm = FALSE)pmin(..., na.rm = FALSE)pmax.int(..., na.rm = FALSE)pmin.int(..., na.rm = FALSE)

Arguments

...

numeric or character arguments (see Note).

na.rm

a logical indicating whether missing values should beremoved.

Details

max andmin return the maximum or minimum ofallthe values present in their arguments, asinteger ifall arelogical orinteger, asdouble ifall are numeric, and character otherwise.

Ifna.rm isFALSE anNA value in any of thearguments will cause a value ofNA to be returned, otherwiseNA values are ignored.

The minimum and maximum of a numeric empty set are+Inf and-Inf (in this order!) which ensurestransitivity, e.g.,min(x1, min(x2)) == min(x1, x2). For numericxmax(x) == -Inf andmin(x) == +Infwheneverlength(x) == 0 (after removing missing values ifrequested). However,pmax andpmin returnNA if all the parallel elements areNA even forna.rm = TRUE.

pmax andpmin take one or more vectors (or matrices) asarguments and return a single vector giving the ‘parallel’maxima (or minima) of the vectors. The first element of the result isthe maximum (minimum) of the first elements of all the arguments, thesecond element of the result is the maximum (minimum) of the secondelements of all the arguments and so on. Shorter inputs (of non-zerolength) are recycled if necessary. Attributes (seeattributes: such asnames ordim) are copied from the first argument (if applicable,e.g.,not for anS4 object).

pmax.int andpmin.int are faster internal versions onlyused when all arguments are atomic vectors and there are no classes:they drop all attributes. (Note that all versions fail for raw andcomplex vectors since these have no ordering.)

max andmin are generic functions: methods can bedefined for them individually or via theSummary group generic. For this towork properly, the arguments... should be unnamed, anddispatch is on the first argument.

By definition the min/max of a numeric vector containing anNaNisNaN, except that the min/max of any vector containing anNA isNA even if it also contains anNaN.Note thatmax(NA, Inf) == NA even though the maximum would beInf whatever the missing value actually is.

Character versions are sorted lexicographically, and this depends onthe collating sequence of the locale in use: the help for‘Comparison’ gives details. The max/min of an emptycharacter vector is defined to be characterNA. (One couldargue that as"" is the smallest character element, the maximumshould be"", but there is no obvious candidate for theminimum.)

Value

Formin ormax, a length-one vector. Forpmin orpmax, a vector of length the longest of the input vectors, orlength zero if one of the inputs had zero length.

The type of the result will be that of the highest of the inputs inthe hierarchy integer < double < character.

Formin andmax if there are only numeric inputs and allare empty (after possible removal ofNAs), the result is double(Inf or-Inf).

S4 methods

max andmin are part of the S4Summary group generic. Methodsfor them must use the signaturex, ..., na.rm.

Note

‘Numeric’ arguments are vectors of type integer and numeric,and logical (coerced to integer). For historical reasons,NULLis accepted as equivalent tointeger(0).

pmax andpmin will also work on classed S3 or S4 objectswith appropriate methods for comparison,is.na andrep(if recycling of arguments is needed).

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)The New S Language.Wadsworth & Brooks/Cole.

See Also

range (both min and max) andwhich.min (which.max) for thearg min,i.e., the location where an extreme value occurs.

‘plotmath’ for the use ofmin in plot annotation.

Examples

require(stats); require(graphics) min(5:1, pi) #-> one numberpmin(5:1, pi) #->  5  numbersx <- sort(rnorm(100));  cH <- 1.35pmin(cH, quantile(x)) # no namespmin(quantile(x), cH) # has namesplot(x, pmin(cH, pmax(-cH, x)), type = "b", main =  "Huber's function")cut01 <- function(x) pmax(pmin(x, 1), 0)curve(      x^2 - 1/4, -1.4, 1.5, col = 2)curve(cut01(x^2 - 1/4), col = "blue", add = TRUE, n = 500)## pmax(), pmin() preserve attributes of *first* argumentD <- diag(x = (3:1)/4) ; n0 <- numeric()stopifnot(identical(D,  cut01(D) ),          identical(n0, cut01(n0)),          identical(n0, cut01(NULL)),          identical(n0, pmax(3:1, n0, 2)),          identical(n0, pmax(n0, 4)))

What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2026 Movatter.jp