Re: [R] function order

From: Dennis Murphy <djmuser_at_gmail.com>
Date: Wed, 06 Apr 2011 05:00:33 -0700

Hi:

Try this:

abc<-cbind(c(1,6,2),c(2,5,3),c(3,2,1))
abc[order(abc[, 1], decreasing = TRUE), ]

     [,1] [,2] [,3]

[1,]    6    5    2
[2,]    2    3    1
[3,]    1    2    3

HTH,
Dennis

On Wed, Apr 6, 2011 at 3:35 AM, Yan Jiao <y.jiao_at_ucl.ac.uk> wrote:

> Dear All
>
> I'm trying to sort a matrix using function order,
> Some thing really odd:
>
> e.g.
> abc<-cbind(c(1,6,2),c(2,5,3),c(3,2,1))## matrix I want to sort
>
> if I do
> abc[ order(abc[,3]), increasing = TRUE]
>
> the result is correct
> [,1] [,2] [,3]
> [1,] 2 3 1
> [2,] 6 5 2
> [3,] 1 2 3
>
> But if I want to sort in decresing order:
> abc[ order(abc[,3]), decreasing = TRUE]
>
> the result is wrong
> [,1] [,2] [,3]
> [1,] 2 3 1
> [2,] 6 5 2
> [3,] 1 2 3
>
> Also if I use
> abc[ order(abc[,3]), increasing = FALSE]
> it returns nothing
> [1,]
> [2,]
> [3,]
>
> Why is that?
>
>
> Many thanks
>
> Yan
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>

        [[alternative HTML version deleted]]



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. Received on Wed 06 Apr 2011 - 12:04:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 06 Apr 2011 - 12:20:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive