binaryapply_byname {matsbyname} | R Documentation |
Apply a binary function "by name"
Description
If either a
or b
is missing or NULL
,
0
is passed to FUN
in its place.
Note that if either a
and b
are lists, elements must be named the same.
The names of list elements of a
are applied to the output.
Usage
binaryapply_byname(
FUN,
a,
b,
.FUNdots = NULL,
match_type = c("all", "matmult", "none"),
set_rowcoltypes = TRUE,
.organize = TRUE
)
Arguments
FUN |
a binary function to be applied "by name" to |
a |
the first operand for |
b |
the second operand for |
.FUNdots |
a list of additional named arguments passed to |
match_type |
one of "all", "matmult", or "none".
When both |
set_rowcoltypes |
tells whether to apply row and column types from |
.organize |
a boolean that tells whether or not to automatically
complete |
Value
the result of applying FUN
"by name" to a
and b
.
Examples
productnames <- c("p1", "p2")
industrynames <- c("i1", "i2")
U <- matrix(1:4, ncol = 2, dimnames = list(productnames, industrynames)) %>%
setrowtype("Products") %>% setcoltype("Industries")
Y <- matrix(1:4, ncol = 2, dimnames = list(rev(productnames), rev(industrynames))) %>%
setrowtype("Products") %>% setcoltype("Industries")
sum_byname(U, Y)
binaryapply_byname(`+`, U, Y)