Learn R Programming

matricks

Useful tricks for matrix

manipulation

Installation

devtools::install_github('krzjoa/matricks')

Usage

Main matricks functions are m and v, which provide convenient API to create matrices and vectors.
Why should we write:

matrix(c(5, 6, 7,
         8, 0, 9,
         3, 7, 1), nrow = 3, byrow = TRUE)
#>      [,1] [,2] [,3]
#> [1,]    5    6    7
#> [2,]    8    0    9
#> [3,]    3    7    1

if we can simply create such a matrix like that:

library(matricks)

m(5, 6, 7|
  8, 0, 9|
  3, 7, 1)
#>      [,1] [,2] [,3]
#> [1,]    5    6    7
#> [2,]    8    0    9
#> [3,]    3    7    1

v function is an useful shortcut for creating vertical vectors (single columns)

v(1,2,3)
#>      [,1]
#> [1,]    1
#> [2,]    2
#> [3,]    3
v(1:5)
#>      [,1]
#> [1,]    1
#> [2,]    2
#> [3,]    3
#> [4,]    4
#> [5,]    5

Setting values in easier with matricks

mat <- matrix(0, 3, 3)
set_values(mat, c(1, 2) ~ 0.5, c(3, 1) ~ 7)
#>      [,1] [,2] [,3]
#> [1,]    0  0.5    0
#> [2,]    0  0.0    0
#> [3,]    7  0.0    0

Copy Link

Version

Install

install.packages('matricks')

Monthly Downloads

244

Version

0.8.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Krzysztof Joachimiak

Last Published

February 23rd, 2020

Functions in matricks (0.8.2)

runif_same_dims

Create matrix of random values with dimensions copied from an existing matrix
repetitions

Repeat columns or rows
rboolm

Create matrix of random choosen boolean values
v

A shortcut to create a vertical vector
plot_matrix

Plot a matrix
with_same_dims

Create new matrix copying dimensions from the existing one
set_values

Set multiple values useing one function call
seq_matrix

Return a sequence of pairs (value, index vector)
runifm

Create matrix of random values drawn from uniform distribution
matrix_idx

Get available marix indices
neighbour_idx_matrix

Create matrix of lists, where each one contains list of neighbour field coordinates
at

Set or get matrix value at index vector
antidiag

Matrix antidiagonals
binding

Bind vector, single values and matrices
operators

Binary operations on matrices/vectors
neighbour_idx

Get all indices in neighbourhood
m

A shortcut to create matrix defining rows
is_idx_possible

Is idx possible in given matrix?