vec {lazy.mat}R Documentation

Vectorization of a matrix

Description

Vectorization of a matrix

Usage

vec(A, byrow = 0)

Arguments

A

A matrix or vector

byrow

= 1 to get the row-major vectorization

Details

When A is a vector it will be converted to a column vector.
Same as matrix(A,,1).

The result is a column vector consisting of c(A).

vec(A, byrow=1) is equal to vec(t(A)).

Can be used with a character matrix.

Value

A column vector of the size nrow(A)*ncol(A) times 1

Examples

vecA=vec(demomat(3,2))
A=matrix(vecA,3)

vecA2=vec(demomat(3,2), byrow=1)
A2=matrix(vecA2,3,,byrow=1)

identical(A,A2)

identical( vec(A,byrow=1),vec(t(A)) )


# converting to a native vector with name
vecA=vec(demomat(3,2))
vecA1=vecA[,1,drop=1]#'
# without name
vecA2=c(vecA)

identical(vecA1,vecA2)
print(vecA1)
print(vecA2)


[Package lazy.mat version 0.1.4 Index]