Hello, I have a matrix results with dimension 1x9 double matrix XLB XLE XLF XLI 1 53.3089 55.77923 37.64458 83.08646 I'm trying to order this matrix> print(order(results))[1] 3 1 2 4 how can the function order return the columnname XLF XLB XLE XLI instead of 3 1 2 4 any idea ? Thank you in advance --
names(results)[order(results)] Michael On Fri, Dec 2, 2011 at 2:45 PM, Martin Bauer <Bauermartin at gmx.at> wrote:> Hello, > > > I have a matrix results with dimension 1x9 double matrix > > ? ? ? ? XLB ? ? ? XLE ? ? ? ? ? ? XLF ? ? ? ? XLI > 1 ? ? ? 53.3089 ?55.77923 ? ? ? 37.64458 ? ? 83.08646 > > I'm trying to order this matrix > >> print(order(results)) > [1] 3 1 2 4 > > how can the function order return the columnname XLF ? XLB ? XLE ?XLI ?instead of 3 1 2 4 > > any idea ? > > Thank you in advance > -- > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
With similar data, since you didn't include reproducible example of your own:> results <- matrix(c(53, 55, 37, 83), nrow=1) > colnames(results) <- letters[1:4] > resultsa b c d [1,] 53 55 37 83> order(results)[1] 3 1 2 4> colnames(results)[order(results)][1] "c" "a" "b" "d" On Fri, Dec 2, 2011 at 2:45 PM, Martin Bauer <Bauermartin at gmx.at> wrote:> Hello, > > > I have a matrix results with dimension 1x9 double matrix > > ? ? ? ? XLB ? ? ? XLE ? ? ? ? ? ? XLF ? ? ? ? XLI > 1 ? ? ? 53.3089 ?55.77923 ? ? ? 37.64458 ? ? 83.08646 > > I'm trying to order this matrix > >> print(order(results)) > [1] 3 1 2 4 > > how can the function order return the columnname XLF ? XLB ? XLE ?XLI ?instead of 3 1 2 4 > > any idea ? > > Thank you in advance > -- >-- Sarah Goslee http://www.functionaldiversity.org