kos59125 / naturalsort

Natural ordering in R
Other
8 stars 3 forks source link

Have naturalorder consider decimals and scientific notation #7

Open billdenney opened 8 years ago

billdenney commented 8 years ago

Currently, naturalorder considers only integers. When decimals or scientific notation is given, it sorts as though all non-digit characters are text-- including period and negative numbers.

> naturalorder(c("2", "1", "0"))
[1] 3 2 1
> naturalorder(c("0.10", "0.020", "0.0030"))
[1] 1 2 3
> > naturalorder(c("-0.10", "-0.010", "-0.0010"))
[1] 3 2 1

Would you be interested in a pull request that would make both of these work as expected from a floating point interpretation? If you wouldn't want it to always apply, perhaps an option on how to interpret the order such as a new option: interpretation=c("natural", "integers", "real", "scientific")

And, a different regular expression would be associated with each.

kos59125 commented 8 years ago

I'm interested in your PR. What happens to vectors such like c("1.0.1", "1.1.0", "1.0") for each interpretation?

billdenney commented 8 years ago

The way I'm thinking of it, the order would be as follows for each interpretation:

Where it would get more complex is something like the c("1.0-1", "1.1-0", "1.0", "1.0-0")