r - How to order columns in a matrix based on final column values? -


i'm trying reorder existing matrices in r based on final column values can't seem find solution. i've tried order(), no luck. i'm overlooking something. ideas? instance, let's create matrix 5 columns of data:

> <-matrix(100+rnorm(50),10,5) >            [,1]      [,2]      [,3]      [,4]      [,5]  [1,] 101.26878  99.36657  99.32874  99.46449 101.46698  [2,] 102.28284 102.62506 100.21430 100.54780 100.14608  [3,]  99.25180 100.93911 101.31455  99.92939  99.87537  [4,]  99.69423  99.17830  99.20230  99.42162 100.70614  [5,]  99.03745  99.95904 100.85773  98.39691 100.84777  [6,] 100.09040 101.66841  98.73320  97.41576  99.36144  [7,]  99.94181 100.18932 101.26947  99.81551  99.30574  [8,]  99.15694  98.24990  98.81500  99.26529 100.72547  [9,] 100.52822  99.43562 101.73370  98.32482  99.30498 [10,] 100.37140  99.54621  99.37048  99.43794 101.28328 

how reorder columns based on final values , save results in matrix? instance, column [,5] has highest final value (101.28328) listed first, in extreme left; column [,1] second, , on. thanks!

this work:

a[,order(a[nrow(a),])] 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -