mop: Mop an array with multiple functions

Description Usage Arguments Details See Also Examples

View source: R/mop.R

Description

Based on sweep, operate on an array by a summary statistic function.

Usage

1
mop(x, m, s, f, ...), smop(x, s, f, ...), mop_div(x, s, ...)

Arguments

x

An array.

m

Margin. 1 for rows, 2 for columns.

s

A summary statistic function such as mean.

f

A function to be "swept" or "mopped" out, typically a binary operator.

...

Arguments passed to sweep.

Details

Essentially, mop is a wrapper for sweep(x, MARGIN, apply(...), FUN). Useful for indexing variables by their means, for example, so that the magnitude of a value relative to its average is known. The function smop simplifies mop by operating only on columns. The function mop_div simplifies mop further by operating only on columns and assuming f to be `/`.

See Also

https://github.com/robertschnitman/afp, sweep

Examples

1
2
mop(mtcars, 2, mean, `/`) # == sweep(mtcars, 2, apply(mtcars, 2, mean), `/`)
mop(mtcars, 2, median, `/`)

robertschnitman/afp documentation built on Aug. 9, 2020, 9:46 a.m.