pow_byname: Powers of matrix elements

View source: R/Binary.R

pow_bynameR Documentation

Powers of matrix elements

Description

Gives the result of raising all elements of a matrix or list of matrices to a power.

Usage

pow_byname(a, pow)

Arguments

a

a matrix of list of matrices

pow

the power to which elements of a will be raised

Value

a with each element raised to pow

Examples

library(dplyr)
pow_byname(2, 3)
m <- matrix(2, nrow = 2, ncol = 3, dimnames = list(paste0("r", 1:2), paste0("c", 1:3))) %>% 
  setrowtype("rows") %>% setcoltype("cols")
pow_byname(m, 2)
DF <- data.frame(m = I(list()), pow = I(list()))
DF[[1, "m"]] <- m
DF[[2, "m"]] <- m
DF[[1, "pow"]] <- 0.5
DF[[2, "pow"]] <- -1
DF %>% mutate(
  sqrtm = pow_byname(m, 0.5),
  mtopow = pow_byname(m, pow)
)

matsbyname documentation built on Oct. 19, 2023, 5:11 p.m.