apply(x, MARGIN, FUN, ...)
x
| the array to be used. |
MARGIN
|
a vector giving the subscripts which the
function will be applied over.
1 indicates rows, 2 indicates columns,
c(1,2) indicates rows and columns.
|
FUN
|
the function to be applied.
In the case of functions like + ,
%*% , etc., the function name must be quoted.
|
...
|
optional arguments to FUN .
|
FUN
returns a vector of length n
, then
apply
returns an array of dimension c(n,dim(x)[MARGIN])
if
n > 1
. If LANG(n EQUALS 1), LANG(apply) returns a vector if
MARGIN
has length 1 and an array of dimension dim(x)[MARGIN]
otherwise.
lapply
, tapply
, sweep
.