Sebastian Bauer
2011-Aug-24 15:09 UTC
[R] Function rank() for data frames (or multiple vectors)?
Hello, I'd like to rank rows of a data frame similar to what rank() does for vectors. However, ties should be broken by columns that I specify. If it is not possible to break a ties (because the row data is essentially the same), I'd like to have the same flexibility that rank() offers. Is there an elegant solution to this simple problem in R? Basically, what I need is a mixture of order() and rank(). While the former allows to specify multiple vectors, it doesn't provide the flexibility of rank() such that I can specify what happens if ties can not be broken. Thanks for your help! Best, Sebastian
David Winsemius
2011-Aug-24 16:44 UTC
[R] Function rank() for data frames (or multiple vectors)?
On Aug 24, 2011, at 11:09 AM, Sebastian Bauer wrote:> Hello, > > I'd like to rank rows of a data frame similar to what rank() does > for vectors. However, ties should be broken by columns that I > specify. If it is not possible to break a ties (because the row data > is essentially the same), I'd like to have the same flexibility that > rank() offers. Is there an elegant solution to this simple problem > in R? Basically, what I need is a mixture of order() and rank(). > While the former allows to specify multiple vectors, it doesn't > provide the flexibility of rank() such that I can specify what > happens if ties can not be broken.An example of this "simple problem" would clarify this greatly. I cannot tell what "flexibility" in 'rank' is missing in 'order'. -- David Winsemius, MD West Hartford, CT