sweep {base}R Documentation

Sweep out Array Summaries


Return an array obtained from an input array by sweeping out a summary statistic.


sweep(x, MARGIN, STATS, FUN="-", ...)


x an array.
MARGIN a vector of indices giving the extents of x which correspond to STATS.
STATS the summary statistic which is to be swept out.
FUN the function to be used to carry out the sweep. In the case of binary operators such as "/" etc., the function name must backquoted or quoted. (FUN is found by a call to match.fun.)
... optional arguments to FUN.


An array with the same shape as x, but with the summary statistics swept out.


Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also

apply on which sweep used to be based; scale for centering and scaling.


require(stats) # for median
med.att <- apply(attitude, 2, median)
sweep(data.matrix(attitude), 2, med.att)# subtract the column medians

[Package base version 2.5.0 Index]