Learn R Programming

mosaic (version 1.9.1)

aggregatingFunction1or2: 1- or 2-ary aggregating functions

Description

aggregatingFunction1or2() creates statistical summaries for functions like var() that can have either 1 or 2 numeric vector inputs.

Usage

aggregatingFunction1or2(
  fun,
  output.multiple = FALSE,
  na.rm = getOption("na.rm", FALSE)
)

Arguments

fun

a function that takes 1 or 2 numeric vectors and computes a summary statistic, returning a numeric vector of length 1.

output.multiple

a boolean indicating whether fun returns multiple values

na.rm

the default value for na.rm in the resulting function.

Details

This was designed primarily to support var which can be used to compute either the variance of one variable or the covariance of two variables. The logic of the resulting function is this: 1) If the first two arguments are both formulas, then those formulas are evaluated (with data) to compute the covariance; (2) If the first argument is a formula, and the second is NULL, then the formula and data are used to create the necessary call(s) to fun; (3) Else everything is simply passed to fun for evaluation.