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.
binaryapply_byname( FUN, a, b, .FUNdots = NULL, match_type = c("all", "matmult", "none"), set_rowcoltypes = TRUE, .organize = TRUE )
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 |
the result of applying FUN
"by name" to a
and b
.
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)#> i1 i2 #> p1 5 5 #> p2 5 5 #> attr(,"rowtype") #> [1] "Products" #> attr(,"coltype") #> [1] "Industries"binaryapply_byname(`+`, U, Y)#> i1 i2 #> p1 5 5 #> p2 5 5 #> attr(,"rowtype") #> [1] "Products" #> attr(,"coltype") #> [1] "Industries"