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