-5

Got a basic R for-loop matrix question:

My matrix looks something like this:

2    4    3
1    5    7

All I want is to print these elements row wise and not column wise. The answer should be like 2 4 3 1 5 7. All I try I get the result column wise i.e `2 1 4 5 3 7. Since m just beginning R wondering if it can be done by just for-loop which loops column wise and not row-wise

1 Answers1

-1
m <- matrix(c(2, 4, 3, 1, 5, 7), 2, 3, byrow=T)
as.vector(m)

or

c(m[1, 1:3], m[2, 1:3])
s_baldur
  • 29,441
  • 4
  • 36
  • 69