# 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)
)
Run the code above in your browser using DataLab