fractionize_byname: Compute fractions of matrix entries

View source: R/Unary.R

fractionize_bynameR Documentation

Compute fractions of matrix entries

Description

This function divides all entries in a by the specified sum, thereby "fractionizing" the matrix.

Usage

fractionize_byname(a, margin)

Arguments

a

the matrix to be fractionized

margin

If 1 (rows), each entry in a is divided by its row's sum. If 2 (columns), each entry in a is divided by its column's sum. If c(1,2) (both rows and columns), each entry in a is divided by the sum of all entries in a.

Value

a fractionized matrix of same dimensions and same row and column types as a.

Examples

M <- matrix(c(1, 5,
              4, 5),
            nrow = 2, ncol = 2, byrow = TRUE, 
            dimnames = list(c("p1", "p2"), c("i1", "i2"))) %>% 
            setcoltype("Products") %>% setrowtype("Industries")
fractionize_byname(M, margin = c(1,2))
fractionize_byname(M, margin = 1)
fractionize_byname(M, margin = 2)

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