1

I'd like ot vectorize a matrix in order to get the values "per rows". For example:

mat = matrix(1:4,ncol=2)
mat
     [,1] [,2]
[1,]    1    3
[2,]    2    4

c(mat) # or as.vector(mat). Both give the values "per columns"
[1] 1 2 3 4

I would like to get this:

[1] 1 3 2 4
Remi.b
  • 17,389
  • 28
  • 87
  • 168

2 Answers2

2

Transpose your matrix first, such as c(t(mat)).

Thomas
  • 43,637
  • 12
  • 109
  • 140
cogitovita
  • 1,685
  • 1
  • 15
  • 15
-2

Fill matrix by row

matrix(1:4,ncol=2 , byrow=TRUE)  # matrix is filled by rows.

enter image description here

shakthydoss
  • 2,551
  • 6
  • 27
  • 36
  • 3
    @shakthydoss there are better ways to do that. Check out [**how to make a great reproducible example**](http://stackoverflow.com/q/5963269/1478381) for examples/ideas/methods. – Simon O'Hanlon Dec 16 '13 at 13:50