50% off | Unlimited Data & AI Learning
Get 50% off unlimited learning

nnspat (version 0.1.2)

mat2vec: 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 k2×2 matrix

Usage

mat2vec(ct, byrow = TRUE)

Value

A list with two elements

vec

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

ind

The k2×2 matrix of entry indices (in the original matrix ct) whose i-th row corresponds to the i-th entry in vec.

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.

Author

Elvan Ceyhan

See Also

ind.nnsym and ind.seg.coeff,

Examples

Run this code
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)

Run the code above in your browser using DataLab