Gives the result of raising all elements of a matrix or list of matrices to a power.
elementpow_byname(a, pow)
a | a matrix of list of matrices |
---|---|
pow | the power to which elements of |
a
with each element raised to pow
#> [1] 8m <- matrix(2, nrow = 2, ncol = 3, dimnames = list(paste0("r", 1:2), paste0("c", 1:3))) %>% setrowtype("rows") %>% setcoltype("cols") elementpow_byname(m, 2)#> c1 c2 c3 #> r1 4 4 4 #> r2 4 4 4 #> attr(,"rowtype") #> [1] "rows" #> attr(,"coltype") #> [1] "cols"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 = elementpow_byname(m, 0.5), mtopow = elementpow_byname(m, pow) )#> m pow sqrtm #> 1 2, 2, 2,.... 0.5 1.414214, 1.414214, 1.414214, 1.414214, 1.414214, 1.414214 #> 2 2, 2, 2,.... -1 1.414214, 1.414214, 1.414214, 1.414214, 1.414214, 1.414214 #> mtopow #> 1 1.414214, 1.414214, 1.414214, 1.414214, 1.414214, 1.414214 #> 2 0.5, 0.5, 0.5, 0.5, 0.5, 0.5