Change the order of the columns - rows of an R matrix

1

I need to add to this matrix a row of 0 (zeros) above and a column of 0 on the left.

I tried to do it like this ...

R <- rbind(Hxx, 0)
R <- cbind(R, 0)

... but I add the row and column at the end. When I had them in the end, I tried with R[,(1,8)]<- R[,(8,1)] , but it did not work.

How to solve this?

    
asked by Sanlla 18.11.2016 в 13:06
source

1 answer

2

Your problem is due to the order of the arguments.

If your matrix is Hxx , then rbind(Hxx, 0) will put in the rows first Hxx and then 0, this way the row of 0s will be at the end. So you have to do rbind(0, Hxx) . In the same way it must be R <- cbind(0, R) so that the column of zeros is on the left.

Remember that both rbind and cbind are sensitive to the order of the arguments!

    
answered by 18.11.2016 / 15:57
source