create_origin_fn {rearrr} | R Documentation |
Create origin_fn function
Description
Creates a function that applies a supplied function to all input vectors.
Usage
create_origin_fn(fn, ...)
Arguments
fn |
Function to apply to each dimension. Should return a numeric scalar. |
... |
Arguments for |
Value
Function with the dots (...
) argument that applies the `fn`
function to
each element in ...
(usually one vector per dimension).
Author(s)
Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk
See Also
Other coordinate functions:
centroid()
,
is_most_centered()
,
midrange()
,
most_centered()
Other function creators:
create_dimming_fn()
,
create_n_fn()
Examples
# Attach packages
library(rearrr)
# Set seed
set.seed(1)
# Create three vectors
x <- runif(10)
y <- runif(10)
z <- runif(10)
# Create origin_fn that gets the median of each dimension
median_origin_fn <- create_origin_fn(median)
# Use median_origin_fn
median_origin_fn(x, y, z)
# Should be the same as
c(median(x), median(y), median(z))
# Use mean and ignore missing values
mean_origin_fn <- create_origin_fn(mean, na.rm = TRUE)
# Add missing values
x[[2]] <- NA
y[[5]] <- NA
# Use mean_origin_fn
mean_origin_fn(x, y, z)
# Should be the same as
c(mean(x, na.rm = TRUE),
mean(y, na.rm = TRUE),
mean(z, na.rm = TRUE)
)
[Package rearrr version 0.3.4 Index]