[R] sorting matrix by sets rows

Adrian Johnson oriolebaltimore at gmail.com
Sun Feb 7 00:45:16 CET 2016


Hello:
sorry I've been trying to sort a matrix to make waterfall plot using
barplot function.

I have have 30x5 matrix.    Rows are samples and columns are results
for a test as numeric vector.

I want sort matrix by column. For example, first I want to sort column
1, in decreasing values where column 5 $ Cluster == 1 and then again
decreasing by those rows with column == 2.

How can I sort the column, by decreasing order, first by samples where
clusters belong to 1 and then sort rows that belong to cluster 2.

Thanks
adrian

Example data is given as dput.

structure(list(Byers_EMT = c(4003.034387, 3768.281515, 3050.928331,
3176.920101, 2934.668097, 4823.117405, 3223.478884, 4241.000063,
2283.048518, 4338.528845, 3036.77349, 4300.743191, 3368.661555,
4658.908373, 4388.761884, 4081.057216, 3096.255942, 4705.843311,
4198.967015, 4273.724545, 3748.975301, 3686.148902, 4538.225296,
3799.86772, 4055.619424, 2242.591587, 3240.442781, 4881.301143,
4715.630605, 2390.426857), GOTZ_EMT = c(-462.4488505, 221.7113983,
382.0156009, -213.9475246, 412.4785725, -876.3339338, -428.6239051,
-904.5665305, 1095.115995, -74.39566533, 462.2938373, -1114.129494,
490.1939685, -686.8375546, -265.4837211, -19.85851263, -143.0651772,
-474.8515908, 59.99735, -245.9500041, -116.9701906, 164.9975774,
-353.3706953, 296.4978516, -225.2971721, 841.0098397, 311.3738267,
-497.1874598, -507.8169759, 893.5205575), GOT_EMT = c(3647.970274,
4308.586674, 4284.509207, 3864.143199, 4546.207066, 2857.187171,
3689.57683, 3342.042018, 5081.829902, 3984.897048, 4300.881677,
3296.588856, 4187.054703, 3586.055372, 3614.984328, 4478.424137,
3725.619911, 3922.904098, 4055.279616, 3915.446721, 4087.219866,
4243.127381, 4029.672242, 4331.676433, 4034.186023, 4718.144867,
4627.10284, 3948.356452, 3856.944245, 5041.236254), GOT_DN_EMT = c(4110.419124,
4086.875276, 3902.493606, 4078.090724, 4133.728494, 3733.521105,
4118.200735, 4246.608548, 3986.713907, 4059.292713, 3838.587839,
4410.71835, 3696.860734, 4272.892927, 3880.468049, 4498.282649,
3868.685088, 4397.755689, 3995.282266, 4161.396725, 4204.190056,
4078.129803, 4383.042937, 4035.178581, 4259.483195, 3877.135027,
4315.729014, 4445.543912, 4364.761221, 4147.715697), Cluster = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L)), .Names = c("Byers_EMT",
"GOTZ_EMT", "GOT_EMT", "GOT_DN_EMT", "Cluster"), class = "data.frame",
row.names = c("BA.5555",
"CN.5356", "CR.7398", "CR.7402", "CV.7247", "CN.6988", "CV.5440",
"BA.6869", "CN.6022", "CN.5360", "CR.7399", "CV.7250", "CV.7440",
"CV.7242", "CN.4739", "CV.7421", "CV.5441", "CR.7364", "CN.4727",
"F7.7848", "CV.7245", "CR.7370", "CR.7371", "CV.7415", "CV.6935",
"CV.5444", "CV.5978", "CN.4738", "CV.7089", "CN.6989"))



More information about the R-help mailing list