Open robertschnitman opened 6 years ago
To note, we can replicate the example with sweep() and sapply():
sweep(mtcars, 2, sapply(mtcars, mean), `/`)
09/20/2018 EDIT: Thus,
# f = primary function, most likely a binary operator.
# s = summary statistic function
meep <- function(f, s, x, m) sweep(x, m, apply(x, m, s), f)
# Worth noting that ?sweep has an example with apply().
However, the above draft does not solve the multivariate case. Is one even necessary? The point of sweep() is to "sweep out" (i.e. map a function to) the rows or columns by the associated summary statistic--there is not a tertiary consideration. Perhaps the benefit of meep() is the convenience of apply() being written within the function? This benefit comes at the cost of being unable to input a list of non-function elements for "s" as with sweep().
Use sweep()/apply() combination and rename to "brush" or "mop"--because we are applying the same process to each row or column? [09/21/2018 EDIT: grammar].
Based on the previous comment, mop.r has been created. This issue will be left open in case an idea for a true multivariate sweep propagates.
The function sweep() is underrated. So, to expand upon its benefits, how should a multivariate version of sweep() resemble?