This function divides all entries in a
by the specified sum,
thereby "fractionizing" the matrix.
fractionize_byname(a, margin)
a | the matrix to be fractionized |
---|---|
margin | If |
a fractionized matrix of same dimensions and same row and column types as a
.
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))#> i1 i2 #> p1 0.06666667 0.3333333 #> p2 0.26666667 0.3333333 #> attr(,"coltype") #> [1] "Products" #> attr(,"rowtype") #> [1] "Industries"fractionize_byname(M, margin = 1)#> i1 i2 #> p1 0.1666667 0.8333333 #> p2 0.4444444 0.5555556 #> attr(,"coltype") #> [1] "Products" #> attr(,"rowtype") #> [1] "Industries"fractionize_byname(M, margin = 2)#> i1 i2 #> p1 0.2 0.5 #> p2 0.8 0.5 #> attr(,"coltype") #> [1] "Products" #> attr(,"rowtype") #> [1] "Industries"