Description Usage Arguments Value See Also Examples
Like matrix
, mat
creates a matrix from the given set of
values. However, these values can also be represented by a character string,
or a list of vectors. Initially inspired by
NumPy's matrix function.
1 2 3 4 5 6 7 8 9 10 |
x |
A data vector, character string, or a list. |
... |
Aditional optional arguments to be passed on to |
rows |
Logical. If |
sep |
Separator string. Values within each row/column of x are
separated by this string. Default is |
eval |
Logical indicating whether or not the character string contains R
expressions that need to be evaluated. Default is |
A matrix (i.e., an object of class "matrix"
).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # Creating a matrix from a character string
mat("1, 2, 3, 4; 5, 6, 7, 8") # ";" separates rows
mat("1, 2, 3, 4; 5, 6, 7, 8", rows = FALSE) # ";" separates columns
mat("1 2 3 4; 5 6 7 8", sep = "") # use spaces instead of commas
mat(c(1, 2, 3, 4, 5, 6, 7, 8), nrow = 2, byrow = TRUE) # works like matrix too
# Character strings containing R expressions
mat("rnorm(3); rnorm(3)")
mat("rnorm(3); rnorm(3)", eval = TRUE)
mat("1, 2, 3; 4, 5, pi")
mat("1, 2, 3; 4, 5, pi", eval = TRUE)
mat("-1, -.1; -0.1, -1.0")
# Creating a matrix from a list
z1 <- list(1:5, 6:10)
z2 <- list(a = 1:5, b = 6:10)
mat(z1)
mat(z2) # preserves names as row names
mat(z2, rows = FALSE) # preserves names as column names
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.