vectorisation: Vectorisation utitilies

cvecR Documentation

Vectorisation utitilies

Description

Convert between matrix and vector representations

Usage

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

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 14, 2025, 1:12 p.m.