midrange {rearrr}R Documentation

Find the midrange values

Description

[Experimental]

Calculates the midrange for each of the passed vectors/columns.

Midrange is defined as:

(max x + min x) / 2

Usage

midrange(..., cols = NULL, na.rm = FALSE)

Arguments

...

Numeric vectors or a single data.frame.

cols

Names of columns to use when `...` is a single data.frame.

na.rm

Whether to ignore missing values when calculating min and max values. (Logical)

Value

Either a vector with the midrange of each supplied vector or a data.frame with the midrange of each supplied column along with any grouping variables.

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

See Also

Other coordinate functions: centroid(), create_origin_fn(), is_most_centered(), most_centered()

Examples

# Attach packages
library(rearrr)
library(dplyr)

# Set seed
set.seed(1)

# Create three vectors
x <- runif(10)
y <- runif(10)
z <- runif(10)

# Find midrange for each vector
midrange(x, y, z)

#
# For data.frames
#

# Create data frame
df <- data.frame(
  "x" = x,
  "y" = y,
  "z" = z,
  "g" = rep(1:2, each = 5)
)

# Find midrange for each column
midrange(df, cols = c("x", "y", "z"))

# When 'df' is grouped
df %>%
  dplyr::group_by(g) %>%
  midrange(cols = c("x", "y", "z"))

[Package rearrr version 0.3.4 Index]