Makes a function balance the removal of NA
s across multiple input vectors.
Value
A function like f
with a new argument na.rm
. If na.rm = TRUE
then
complete.cases()
is used to remove missing values across all inputs
prior to calling f
.
See also
Other operators:
grouped()
,
quantity_index()
Examples
p1 <- price6[[3]]
p0 <- price6[[2]]
q1 <- quantity6[[3]]
q0 <- quantity6[[2]]
# Balance missing values for a Fisher index
fisher <- balanced(fisher_index)
fisher(p1, p0, q1, replace(q0, 3, NA), na.rm = TRUE)
#> [1] 0.9015449
fisher_index(p1[-3], p0[-3], q1[-3], q0[-3])
#> [1] 0.9015449
# Operators can be combined, but some care may be needed
x <- 1:6
w <- c(1:5, NA)
f <- factor(rep(letters[1:2], each = 3))
grouped(\(x, w) balanced(fisher_mean)(x, w, na.rm = TRUE))(x, w, group = f)
#> [1] 1.954017 1.954017 1.954017 4.499657 4.499657 4.499657
balanced(grouped(fisher_mean))(x, w, group = f, na.rm = TRUE)
#> [1] 1.954017 1.954017 1.954017 4.499657 4.499657