Skip to content
  • rray_pmax() computes the elementwise maximum of two arrays.

  • rray_pmin() computes the elementwise minimum of two arrays.

Usage

rray_pmax(x, y, ..., na_rm = FALSE)

rray_pmin(x, y, ..., na_rm = FALSE)

Arguments

x

An array.

y

An array.

...

These dots are for future extensions and must be empty.

na_rm

If TRUE, missing values are removed before taking the maximum or minimum.

Value

An array with the common dimensions and common type of x and y.

Details

The arrays are broadcast to common dimensions first, so they do not have to be the same shape.

When NA and NaN are both present, NA wins, like rray_max(), rray_min(), max(), and min(). This differs from pmax() and pmin(), which return whichever comes last:

rray_pmax(NA, NaN) # NA
rray_pmax(NaN, NA) # NA

pmax(NA, NaN) # NaN

Examples

x <- array(1:6, c(3L, 2L))

rray_pmax(x, 4L)
#>      [,1] [,2]
#> [1,]    4    4
#> [2,]    4    5
#> [3,]    4    6
rray_pmin(x, 4L)
#>      [,1] [,2]
#> [1,]    1    4
#> [2,]    2    4
#> [3,]    3    4

# Compare each column with a different value through broadcasting
rray_pmax(x, array(c(2L, 5L), c(1L, 2L)))
#>      [,1] [,2]
#> [1,]    2    5
#> [2,]    2    5
#> [3,]    3    6