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, inf_becomes = .Machine$double.xmax)

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.

inf_becomes

A value to be substitute for any Inf produced by division. Default is .Machine$double.xmax. Another reasonable value is Inf. Set to NULL to disable substitution. inf_becomes is passed to hatinv_byname().

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)

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