Calculates column products (the product of all elements in a column) for a matrix.
An optional rowname
for the resulting row vector can be supplied.
If rowname
is NULL
or NA
(the default),
the row name is set to the row type as given by rowtype(a)
.
colprods_byname(a, rowname = NA)
a | a matrix or data frame from which column products are desired. |
---|---|
rowname | name of the output row containing column products. |
a row vector of type matrix
containing the column products of a
.
library(dplyr) M <- matrix(c(1:6), nrow = 2, dimnames = list(paste0("i", 1:2), paste0("c", 3:1))) %>% setrowtype("Industries") %>% setcoltype("Commodities") colprods_byname(M)#> c1 c2 c3 #> Industries 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities"colprods_byname(M, rowname = "E.ktoe")#> c1 c2 c3 #> E.ktoe 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities"M %>% colprods_byname %>% rowprods_byname#> Commodities #> Industries 720 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities"#> [[1]] #> c1 c2 c3 #> Industries 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #> #> [[2]] #> c1 c2 c3 #> Industries 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #>#> [[1]] #> c1 c2 c3 #> E.ktoe 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #> #> [[2]] #> c1 c2 c3 #> E.ktoe 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #>#> [[1]] #> c1 c2 c3 #> Industries 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #> #> [[2]] #> c1 c2 c3 #> Industries 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #>#> [[1]] #> c1 c2 c3 #> Industries 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #> #> [[2]] #> c1 c2 c3 #> Industries 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #>#> c1 c2 c3 #> Industries 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities"colprods_byname(DF$M)#> [[1]] #> c1 c2 c3 #> Industries 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #> #> [[2]] #> c1 c2 c3 #> Industries 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #>colprods_byname(DF$M, "prods")#> [[1]] #> c1 c2 c3 #> prods 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #> #> [[2]] #> c1 c2 c3 #> prods 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #>#> [[1]] #> c1 c2 c3 #> prod 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #> #> [[2]] #> c1 c2 c3 #> prod 30 12 2 #> attr(,"rowtype") #> [1] "Industries" #> attr(,"coltype") #> [1] "Commodities" #>