mat2vec: Conversion of a Matrix to a Vector

View source: R/NNCTFunctions.R

mat2vecR Documentation

Conversion of a Matrix to a Vector

Description

Converts the contingency table (or any matrix) ct to a vector by default row-wise (i.e., by appending each row one after the other) or column-wise, and also returns the entry indices (in the original matrix ct) in a k^2 \times 2 matrix

Usage

mat2vec(ct, byrow = TRUE)

Arguments

ct

A matrix, in particular a contingency table

byrow

A logical argument (default=TRUE). If TRUE, rows of ct are appended to obtain the vector and if FALSE columns of ct are appended to obtain the vector.

Value

A list with two elements

vec

The vectorized form the matrix ct, by default appending the rows of ct

ind

The k^2 \times 2 matrix of entry indices (in the original matrix ct) whose i-th row corresponds to the i-th entry in vec.

Author(s)

Elvan Ceyhan

See Also

ind.nnsym and ind.seg.coeff,

Examples

n<-20  #or try sample(1:20,1)
Y<-matrix(runif(3*n),ncol=3)
ipd<-ipd.mat(Y)
cls<-sample(1:2,n,replace = TRUE)  #or try cls<-rep(1:2,c(10,10))
ct<-nnct(ipd,cls)
ct
mat2vec(ct)
mat2vec(ct,byrow=FALSE)

#an arbitrary 3x3 matrix
M<-matrix(sample(10:20,9),ncol=3)
M
mat2vec(M)
mat2vec(M,byrow=FALSE)


nnspat documentation built on May 29, 2024, 10:03 a.m.