Change the form of a matrix in R

Viewed 36

If I have a matrix of this form

g = matrix(c(1,1,1,0,1,1,0,0,1),3,3,byrow=T)

How can I turn it into a matrix of this form?

g = matrix(c(1,1,1,1,1,0,1,0,0),3,3,byrow=T)
1 Answers

We can reverse the column sequence index and specify it in j

g1 <- g[, ncol(g):1]

Or use rev

g[, rev(seq_len(ncol(g)))]
Related