View source: R/create_origin_fn.R
create_origin_fn | R Documentation |
Creates a function that applies a supplied function to all input vectors.
create_origin_fn(fn, ...)
fn |
Function to apply to each dimension. Should return a numeric scalar. |
... |
Arguments for |
Function with the dots (...
) argument that applies the `fn`
function to
each element in ...
(usually one vector per dimension).
Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk
Other coordinate functions:
centroid()
,
is_most_centered()
,
midrange()
,
most_centered()
Other function creators:
create_dimming_fn()
,
create_n_fn()
# 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)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.