[R] function order

Jim Lemon jim at bitwrit.com.au
Wed Apr 6 14:09:26 CEST 2011


On 04/06/2011 08:35 PM, Yan Jiao 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?
>
Hi Yan,
It is because you have put the "decreasing" argument outside the 
parentheses, and it is not being used in the "order" function.

Jim



More information about the R-help mailing list