prodall_byname: Product of all elements in a matrix

View source: R/Unary.R

prodall_bynameR Documentation

Product of all elements in a matrix

Description

This function is equivalent to ⁠a \%>\% rowprods_byname() \%>\% colprods_byname()⁠, but returns a single numeric value instead of a 1x1 matrix.

Usage

prodall_byname(a)

Arguments

a

The matrix whose elements are to be multiplied.

Value

The product of all elements in a as a numeric.

Examples

library(dplyr)
M <- matrix(2, nrow=2, ncol=2, dimnames = list(paste0("i", 1:2), paste0("c", 1:2))) %>%
  setrowtype("Industry") %>% setcoltype("Product")
prodall_byname(M)
rowprods_byname(M) %>% colprods_byname
# Also works for lists
prodall_byname(list(M,M))
DF <- data.frame(M = I(list()))
DF[[1,"M"]] <- M
DF[[2,"M"]] <- M
prodall_byname(DF$M[[1]])
prodall_byname(DF$M)
res <- DF %>% mutate(
  prods = prodall_byname(M)
)
res$prods

MatthewHeun/byname documentation built on Feb. 17, 2024, 4:51 p.m.