Type: | Package |
Title: | Simple Matrix Construction |
Version: | 1.1.0 |
Author: | Erik-Jan van Kesteren |
Maintainer: | Erik-Jan van Kesteren <e.vankesteren1@uu.nl> |
Description: | Constructing matrices for quick prototyping can be a nuisance, requiring the user to think about how to fill the matrix with values using the matrix() function. The %<-% operator solves that issue by allowing the user to construct matrices using code that shows the actual matrices. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 6.0.1 |
Suggests: | testthat |
NeedsCompilation: | no |
Packaged: | 2018-01-28 12:44:50 UTC; erikj |
Repository: | CRAN |
Date/Publication: | 2018-01-31 21:39:07 UTC |
Construct a matrix from a (formatted) string
Description
Constructing matrices for quick prototyping can be very annoying in R
,
requiring the user to think about how to fill the matrix with values
using the matrix(data, nrow, ncol, byrow)
function. The %<-%
operator solves that issue by allowing the user to construct string matrices
that look like actual matrices.
Usage
var %<-% value
value %->% var
Arguments
var |
the variable to which the matrix will be assigned. Can be an element of a list. |
value |
a matrix in character form to be converted to a numeric matrix. See examples for valid forms. |
See Also
Examples
# Basic usage
M %<-% " 1, 0.2, -0.3, 0.4
0.2, 1, 0.6, -0.4
-0.3, 0.6, 1, 0.4
0.4, -0.4, 0.4, 1"
M
# Variables allowed!
phi <- 1.5
V %<-% "1, 1, 1
1, phi, phi^2
1, phi^2, phi^4"
V
# Lower triangular is made symmetric:
S %<-% " 1
0.5, 1
-0.2, 0.2, 1"
S
# Complex matrices work too:
C %<-% " 1+2i, 2+1i, 3+4i
4+0.5i, 5+2i, 6+4i"
C
# And lastly, if you're a fan of LaTeX and one-liners:
L %<-% "1, 2, 3 \\ 4, 5, 6 \\ 7, 8, 9 \\ 10, 11, 12"
# (although this kind of defeats the WYSIWYG purpose of Massign)
Quickly test matrix multiplication of two matrices interpreted from strings.
Description
Building on Massign's core functionality, the Multiplipe operator ' allows for quick prototyping of matrix multiplications.
Usage
matrix1 %*>% matrix2
Arguments
matrix1 |
a matrix or Massign character matrix that premultiplies |
matrix2 |
a matrix or Massign character matrix that postmultiplies |
See Also
Examples
# Basic usage
"1, 2
3, 4" %*>%
" 0, 1
1, 0"
# Second argument can be a matrix:
"1, 2, pi \\ 3, 4, 1 \\ 3, 2, 1" %*>% diag(c(1, 2, 3))
# Or the first, for that matter:
diag(c(1, 2, 3)) %*>% "1, 2, pi \\ 3, 4, 1 \\ 3, 2, 1"