Md. Sahidul Islam
Md. Sahidul Islam

Reputation: 583

Make a vector from a matrix in R

I make a vector V of length 9 from a matrix A or order 3*3 using its elements row wise. The code i tried.

A<-matrix(1:9,3,3)
V<-c(A[1,],A[2,],A[,3])

But I want to generalized it using loop.

Upvotes: 0

Views: 94

Answers (1)

MrFlick
MrFlick

Reputation: 206167

How about

as.vector(t(A))

just transpose the matrix and convert to vector. Simple.

Upvotes: 1

Related Questions