I have a matrix
df<-matrix(data=c(3,7,5,0,1,0,0,0,0,8,0,9), ncol=2) rownames(df)<-c(\"a\",\"b\",\"c\",\"d\",\"e\",\"f\") [,1] [,2] a 3 0 b 7
order function will help you out, try this:
order
df[order(-df[,1],-df[,2]),] [,1] [,2] b 7 0 c 5 0 a 3 0 e 1 0 f 0 9 d 0 8
The minus before df indicates that the order is decreasing. You will get the same result setting decreasing=TRUE.
df
decreasing=TRUE
df[order(df[,1],df[,2],decreasing=TRUE),]