How to fill the element in matrix by row wise in R

r

#1

I am creating a matrix using the matrix() but while creating the matrix the element are arranging according to column wise but I want it row wise
x<-matrix(1:6,nrow=2,ncol=3)
x
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6

I am getting this but I want 1 2 3 in first row and remaining in second row


#2

Use the byrow argument:

x<-matrix(1:6,nrow=2,ncol=3,byrow=TRUE)

Use

?matrix

Hope this helps!