elementapply_byname {matsbyname} | R Documentation |
Apply a function to an element of a matrix specified by rows and columns
Description
FUN
is applied to the element of a
that is specified by row
and col
.
Usage
elementapply_byname(FUN, a, row, col, .FUNdots = NULL)
Arguments
FUN |
a unary function to be applied to specified rows and columns of |
a |
the argument to |
row |
the row name of the element to which |
col |
the column name of the element to which |
.FUNdots |
a list of additional arguments to |
Details
row
and col
can be any of row or column names or integer indices or a mix of both.
Value
a
, after FUN
has been applied to the element at row
and col
Examples
divide <- function(x, divisor){
x/divisor
}
m <- matrix(c(1:4), nrow = 2, ncol = 2, dimnames = list(c("r1", "r2"), c("c1", "c2"))) %>%
setrowtype("row") %>% setcoltype("col")
elementapply_byname(divide, a = m, row = 1, col = 1, .FUNdots = list(divisor = 2))
elementapply_byname(divide, a = m, row = 1, col = 2, .FUNdots = list(divisor = 10))
elementapply_byname(divide, a = m, row = "r2", col = "c2", .FUNdots = list(divisor = 100))
[Package matsbyname version 0.6.10 Index]