scale_to_reference_fun: Scale values so that they retain the value of a function...

View source: R/sequence_characteristics.R

scale_to_reference_funR Documentation

Scale values so that they retain the value of a function applied to reference values

Description

Scale values so that they retain the value of a function applied to reference values

Usage

scale_to_reference_fun(x, x_ref, fun, na.rm = FALSE)

Arguments

x

Numeric vector. Values to scale.

x_ref

Numeric vector. Values from which the reference value is calculated.

fun

A function or character vector identifying a function.

na.rm

A logical value. Argument is passed to fun.

Value

A numeric vector of the same length as x.

See Also

scale_to_reference_peak_frequency

Examples

x <- c(1:6, 8)
x0 <- c(10, -1)
x0NA <- c(x0, NA)

# Scale to retain value of reference maximum
scale_to_reference_fun(x, x0, fun = max)

# Scale to retain value of reference sum
scale_to_reference_fun(x, x0, fun = sum)

# Scale to retain value of reference mean
scale_to_reference_fun(x, x0, fun = mean)

# Scale to retain value of reference length (mostly nonsensical!)
scale_to_reference_fun(x, x0, fun = length)

# Scale and handle NAs
scale_to_reference_fun(x, x0NA, fun = mean, na.rm = FALSE)
scale_to_reference_fun(x, x0NA, fun = max, na.rm = TRUE)


DrylandEcology/rSW2utils documentation built on Dec. 9, 2023, 10:44 p.m.