0

I have this code snippet in R:

for(i in 1:n-1){
  for(j in 2:n){
     mult = (matrx[j,i]/matrx[i,i])
     vector = matrx[j,] - (matrx[j-1,] * mult)
     print(vector)
     # matrx[j,] = vector
  }
}

The code prints the vector variable correctly, but it does not replace the matrx[j,] with the values in the vector when i equate it to matrx[j,] = vector.

How do i solve this?

skyranch
  • 55
  • 5

1 Answers1

4

Your loop for i is not correct, in your assignment you loop from 0 to n-1 instead of 1 to n-1 which gives the error: add braces around n-1

for(i in 1:(n-1)){
  for(j in 2:n){
     mult = (matrx[j,i]/matrx[i,i])
     vector = matrx[j,] - (matrx[j-1,] * mult)
     print(vector)
     matrx[j,] = vector
  }
}
Wannes Rosiers
  • 1,680
  • 1
  • 12
  • 18