vectorisation: Vectorisation utitilies

Description Usage Arguments Value Examples

Description

Convert between matrix and vector representations

Usage

1
2
3
cvec(A, d = NULL, sparse = FALSE)

rvec(A, d = NULL, sparse = FALSE)

Arguments

A

A matrix or a vector

d

The number of matrix columns

sparse

logical; If TRUE, use Matrix::Matrix to construct matrix output, that detects sparsity. Default: FALSE

Value

If A is a matrix, cvec returns the columnwise vectorisation of A. and rvec returns the rowwise vectorisation of A. If A is a vector, cvec and rvec return a matrix with d columns, filled columnwise for cvec and rowwise for rvec.

Examples

1
2
3
4
5
6
if (interactive()) {
  Ac <- cvec(1:6, 2) # As matrix(1:6, 3, 2, byrow = FALSE)
  Ar <- rvec(1:6, 2) # As matrix(1:6, 3, 2, byrow = TRUE)
  cvec(Ac) # As as.vector(Ac)
  rvec(Ar) # As as.vector(t(Ar))
}

finnlindgren/multiprobit documentation built on June 20, 2020, 6:12 a.m.