0

Consider the following matrix:

matrix <- matrix(1:9, nrow = 3, ncol = 3)

     [,1] [,2] [,3]
[1,]    1    4    7
[2,]    2    5    8
[3,]    3    6    9

For the two first columns ([,1] and [,2]), I want to divide each element until row [3,] with the number in row [3,]. That is, I want to get the following matrix:

     [,1] [,2]
[1,]  1/3  4/6 
[2,]  2/3  5/6

How do I do that in R?

Michael
  • 565
  • 4
  • 11

0 Answers0