Hi, Bill,

Thank you for your reply. The -as.numeric() does not work as I expected.
BA[2] is character with elements like 2A, 2B, 2C, 3, 4A, 4B, 5. I want it to
be sorted as 5, 4B, 4A, 3, 2C, 2B, 2A. The -as.numeric() method produces 5,
3, 2A, 2B, 2C, 4A, 4B.

xtrfm() suggested by Duncan works very well.

Jun

On Fri, Mar 27, 2009 at 8:50 PM, <bill.venab...@csiro.au> wrote:

> Perhaps BA[, 2] is a factor?  What you might need is something like
>
> BA[order(BA[, 1], -as.numeric(BA[, 2]), ]
>
> ?
>
> Bill Venables.
> ________________________________________
> From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On
> Behalf Of Jun Shen [jun.shen...@gmail.com]
> Sent: 28 March 2009 08:26
> To: r-h...@stat.math.ethz.ch
> Subject: [R] Sorting problem
>
> Hi, everyone,
>
> I was trying to sort a data frame by two columns, one increasing, the other
> decreasing  and got an error.
>
> "Error in FUN(left) : invalid argument to unary operator",
>
> The command is "BA[order(BA[1],-BA[2]),]". BA is the data frame. It was
> working if I used increasing on both columns.
>
> Why the decreasing symbol "-" is not working here? Thanks.
>
> --
> Jun Shen PhD
> PK/PD Scientist
> BioPharma Services
> Millipore Corporation
> 15 Research Park Dr.
> St Charles, MO 63304
> Direct: 636-720-1589
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>



-- 
Jun Shen PhD
PK/PD Scientist
BioPharma Services
Millipore Corporation
15 Research Park Dr.
St Charles, MO 63304
Direct: 636-720-1589

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to