This function is a wrapper for attr
so that
setting can be accomplished by the pipe operator (%>%
).
Row types are strings stored in the rowtype
attribute.
setrowtype(a, rowtype)
a | the matrix on which row type is to be set |
---|---|
rowtype | the type of item stored in rows |
a
with rowtype attribute set to rowtype
.
If is.null(rowtype)
, the rowtype attribute is deleted
and subsequent calls to rowtype
will return NULL
.
library(dplyr) commoditynames <- c("c1", "c2") industrynames <- c("i1", "i2") U <- matrix(1:4, ncol = 2, dimnames = list(commoditynames, industrynames)) U %>% setrowtype("Commodities")#> i1 i2 #> c1 1 3 #> c2 2 4 #> attr(,"rowtype") #> [1] "Commodities"#> [[1]] #> i1 i2 #> c1 1 3 #> c2 2 4 #> attr(,"rowtype") #> [1] "Commodities" #> #> [[2]] #> i1 i2 #> c1 1 3 #> c2 2 4 #> attr(,"rowtype") #> [1] "Commodities" #>#> [[1]] #> i1 i2 #> c1 1 3 #> c2 2 4 #> attr(,"rowtype") #> [1] "Commodities" #> #> [[2]] #> i1 i2 #> c1 1 3 #> c2 2 4 #> attr(,"rowtype") #> [1] "Commodities" #>#> [[1]] #> i1 i2 #> c1 1 3 #> c2 2 4 #> attr(,"rowtype") #> [1] "Commodities" #> #> [[2]] #> i1 i2 #> c1 1 3 #> c2 2 4 #> attr(,"rowtype") #> [1] "Commodities" #>#> i1 i2 #> c1 1 3 #> c2 2 4 #> attr(,"rowtype") #> [1] "Commodities"DF$newcol[[2]]#> i1 i2 #> c1 1 3 #> c2 2 4 #> attr(,"rowtype") #> [1] "Commodities"