Converts a matrix into a column vector.
Each element of the matrix becomes an entry in the column vector,
with rows named via the notation
argument.
Callers may want to transpose the matrix first with transpose_byname()
.
vectorize_byname(a, notation)
a | the matrix to be vectorized. |
---|---|
notation | a string vector created by |
a column vector containing all elements of a
, with row names assigned as "rowname sep
colname".
The notation
argument is also applied to rowtype
and coltype
attributes.
m <- matrix(c(1, 5, 4, 5), nrow = 2, ncol = 2, byrow = TRUE, dimnames = list(c("p1", "p2"), c("i1", "i2"))) %>% setrowtype("Products") %>% setcoltype("Industries") m#> i1 i2 #> p1 1 5 #> p2 4 5 #> attr(,"rowtype") #> [1] "Products" #> attr(,"coltype") #> [1] "Industries"#> [,1] #> p1 -> i1 1 #> p2 -> i1 4 #> p1 -> i2 5 #> p2 -> i2 5 #> attr(,"rowtype") #> [1] "Products -> Industries"# If a single number is provided, the number will be returned as a 1x1 column vector # with some additional attributes. vectorize_byname(42, notation = arrow_notation())#> [,1] #> [1,] 42#> $dim #> [1] 1 1 #>