# colprods_byname: Column products, sorted by name In matsbyname: An Implementation of Matrix Mathematics

 colprods_byname R Documentation

## Column products, sorted by name

### Description

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

### Usage

```colprods_byname(a, rowname = NA)
```

### Arguments

 `a` a matrix or data frame from which column products are desired. `rowname` name of the output row containing column products.

### Value

a row vector of type `matrix` containing the column products of `a`.

### Examples

```library(dplyr)
M <- matrix(c(1:6), nrow = 2, dimnames = list(paste0("i", 1:2), paste0("c", 3:1))) %>%
setrowtype("Industries") %>% setcoltype("Commodities")
colprods_byname(M)
colprods_byname(M, rowname = "E.ktoe")
M %>% colprods_byname %>% rowprods_byname
# This also works with lists
colprods_byname(list(M, M))
colprods_byname(list(M, M), rowname = "E.ktoe")
colprods_byname(list(M, M), rowname = NA)
colprods_byname(list(M, M), rowname = NULL)
DF <- data.frame(M = I(list()))
DF[[1,"M"]] <- M
DF[[2,"M"]] <- M
colprods_byname(DF\$M[[1]])
colprods_byname(DF\$M)
colprods_byname(DF\$M, "prods")
res <- DF %>% mutate(
cs = colprods_byname(M),
cs2 = colprods_byname(M, rowname = "prod")
)
res\$cs2
```

matsbyname documentation built on April 2, 2022, 1:06 a.m.