naryapply_byname {matsbyname} | R Documentation |
Apply a function "by name" to any number of operands
Description
Applies FUN
to all operands in ...
.
Other arguments have similar meaning as binaryapply_byname()
.
See details for more information.
Usage
naryapply_byname(
FUN,
...,
.FUNdots = NULL,
match_type = c("all", "matmult", "none"),
set_rowcoltypes = TRUE,
.organize = TRUE,
.summarise = FALSE
)
Arguments
FUN |
a binary function to be applied "by name" to all operands in |
... |
the operands for |
.FUNdots |
a list of additional named arguments passed to |
match_type |
One of "all", "matmult", or "none".
When |
set_rowcoltypes |
Tells whether to apply row and column types from
operands in |
.organize |
A boolean that tells whether or not to automatically
complete operands in |
.summarise |
A boolean that tells whether this call is considered
a summarise operation (like |
Details
If only one ...
argument is supplied,
FUN
must be capable of handling one argument, and
the call is routed to unaryapply_byname()
.
When set_rowcoltypes
is TRUE
,
the rowcoltypes
argument of unaryapply_byname()
is set to "all",
but when set_rowcoltypes
is FALSE
,
the rowcoltypes
argument of unaryapply_byname()
is set to "none".
If finer control is desired, the caller should use unaryapply_byname()
directly.
If more than one argument is passed in ...
,
FUN
must be a binary function, but its use in by naryapply_byname()
is "n-ary."
Arguments match_type
, set_rowcoltypes
, and .organize
have same meaning as for binaryapply_byname()
.
Thus, all of the operands in ...
must obey the rules of type matching
when match_type
is TRUE
.
naryapply_byname()
and cumapply_byname()
are similar.
Their differences can be described by considering a data frame.
naryapply_byname()
applies FUN
to several columns (variables) of the data frame.
For example, sum_byname()
applied to several variables gives another column
containing the sums across each row of the data frame.
cumapply_byname()
applies FUN
to successive entries in a single column.
For example sum_byname()
applied to a single column gives the sum of all numbers in that column.
Value
the result of applying FUN
to all operands in ...
Examples
naryapply_byname(FUN = sum_byname, 2, 3)
naryapply_byname(FUN = sum_byname, 2, 3, 4, -4, -3, -2)
# Routes to unaryapply_byname
naryapply_byname(FUN = `^`, list(1,2,3), .FUNdots = list(2))