[R] Sorting problem

Duncan Murdoch murdoch at stats.uwo.ca
Sat Mar 28 12:53:42 CET 2009


Bill.Venables at csiro.au wrote:
> Perhaps BA[, 2] is a factor?  What you might need is something like
>
> BA[order(BA[, 1], -as.numeric(BA[, 2]), ]
>   

More generally, the xtfrm() function converts a vector into a numeric 
one that sorts in the same order.  It will work on character columns as 
well:

BA[order(BA[, 1], -xtfrm(BA[,2]), ]

Duncan Murdoch
> ?
>
> Bill Venables.
> ________________________________________
> From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Jun Shen [jun.shen.ut at gmail.com]
> Sent: 28 March 2009 08:26
> To: r-help at 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 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.
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list