quotient_byname | R Documentation |
Element-wise division of two matrices.
quotient_byname(dividend, divisor)
dividend |
Dividend matrix or constant |
divisor |
Divisor matrix or constant |
Performs a union and sorting of names of rows and columns for both dividend
and divisor
prior to element division.
Zeroes are inserted for missing matrix elements.
Doing so ensures that
the dimensions of the dividend
and divisor
will be conformable.
A matrix representing the name-wise element quotient of dividend
and divisor
library(dplyr)
quotient_byname(100, 50)
commoditynames <- c("c1", "c2")
industrynames <- c("i1", "i2")
U <- matrix(1:4, ncol = 2, dimnames = list(commoditynames, industrynames)) %>%
setrowtype("Commodities") %>% setcoltype("Industries")
G <- matrix(rev(1:4), ncol = 2, dimnames = list(rev(commoditynames), rev(industrynames))) %>%
setrowtype("Commodities") %>% setcoltype("Industries")
U / G # Non-sensical. Names aren't aligned
quotient_byname(U, G)
quotient_byname(U, 10)
quotient_byname(10, G)
# This also works with lists
quotient_byname(10, list(G,G))
quotient_byname(list(G,G), 10)
quotient_byname(list(U, U), list(G, G))
DF <- data.frame(U = I(list()), G = I(list()))
DF[[1,"U"]] <- U
DF[[2,"U"]] <- U
DF[[1,"G"]] <- G
DF[[2,"G"]] <- G
quotient_byname(DF$U, DF$G)
DF %>% mutate(elementquotients = quotient_byname(U, G))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.