Gives the geometric mean of corresponding entries of a
and b
.
geometricmean_byname(...)
... | operands; constants, matrices, or lists of matrices |
---|
name-wise geometric mean of operands
This function performs a union and sorting of row and column names prior to performing geometric mean. Zeroes are inserted for missing matrix elements.
#> [1] 100geometricmean_byname(10, 1000, 100000)#> [1] 1000commoditynames <- c("c1", "c2") industrynames <- "i1" U <- matrix(c(10, 1000), ncol = 1, nrow = 2, dimnames = list(commoditynames, industrynames)) %>% setrowtype("Commodities") %>% setcoltype("Industries") G <- matrix(c(1e3, 1e5), ncol = 1, nrow = 2, dimnames = list(rev(commoditynames), rev(industrynames))) %>% setrowtype("Commodities") %>% setcoltype("Industries") # Non-sensical. Row and column names not respected. sqrt(U*G)#> i1 #> c1 100 #> c2 10000 #> attr(,"rowtype") #> [1] "Commodities" #> attr(,"coltype") #> [1] "Industries"# Row and column names respected! geometricmean_byname(U, G)#> i1 #> c1 1000 #> c2 1000 #> attr(,"rowtype") #> [1] "Commodities" #> attr(,"coltype") #> [1] "Industries"geometricmean_byname(1000, U)#> i1 #> c1 100 #> c2 1000 #> attr(,"rowtype") #> [1] "Commodities" #> attr(,"coltype") #> [1] "Industries"geometricmean_byname(10, G)#> i1 #> c1 1000 #> c2 100 #> attr(,"rowtype") #> [1] "Commodities" #> attr(,"coltype") #> [1] "Industries"#> [[1]] #> [1] 100 #> #> [[2]] #> [1] 100 #>#> [[1]] #> i1 #> c1 1000 #> c2 1000 #> attr(,"rowtype") #> [1] "Commodities" #> attr(,"coltype") #> [1] "Industries" #> #> [[2]] #> i1 #> c1 1000 #> c2 1000 #> attr(,"rowtype") #> [1] "Commodities" #> attr(,"coltype") #> [1] "Industries" #>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 geometricmean_byname(DF$U, DF$G)#> [[1]] #> i1 #> c1 1000 #> c2 1000 #> attr(,"rowtype") #> [1] "Commodities" #> attr(,"coltype") #> [1] "Industries" #> #> [[2]] #> i1 #> c1 1000 #> c2 1000 #> attr(,"rowtype") #> [1] "Commodities" #> attr(,"coltype") #> [1] "Industries" #>#> U G geomeans #> 1 10, 1000 1000, 1e+05 1000, 1000 #> 2 10, 1000 1000, 1e+05 1000, 1000