rowprods_byname: Row products, sorted by name

View source: R/Unary.R

rowprods_bynameR Documentation

Row products, sorted by name

Description

Calculates row products (the product of all elements in a row) for a matrix. An optional colname for the resulting column vector can be supplied. If colname is NULL or NA (the default), the column name is set to the column type as given by coltype(a).

Usage

rowprods_byname(a, colname = NA)

Arguments

a

A matrix or list of matrices from which row products are desired.

colname

The Name of the output column containing row products.

Value

A column vector of type matrix containing the row products of a

Examples

library(dplyr)
M <- matrix(c(1:6), ncol = 2, dimnames = list(paste0("i", 3:1), paste0("c", 1:2))) %>%
  setrowtype("Industries") %>% setcoltype("Products")
rowprods_byname(M)
rowprods_byname(M, "E.ktoe")
# This also works with lists
rowprods_byname(list(M, M))
rowprods_byname(list(M, M), "E.ktoe")
rowprods_byname(list(M, M), NA)
rowprods_byname(list(M, M), NULL)
DF <- data.frame(M = I(list()))
DF[[1,"M"]] <- M
DF[[2,"M"]] <- M
rowprods_byname(DF$M[[1]])
rowprods_byname(DF$M)
ans <- DF %>% mutate(rs = rowprods_byname(M))
ans
ans$rs[[1]]
# Nonsensical
## Not run: rowprods_byname(NULL)

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