Reorder the columns of a matrix

Hi, I want to reorder the columns of a matrix based on the value in the second row (First row is the titles of the columns, the matrix has only 2 rows)
thanks in advance!


(example <- matrix(c("titleY","titleX","v2","v1"),nrow=2,byrow = TRUE))
example[,order(example[2,])]
1 Like

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.