Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Have naturalorder consider decimals and scientific notation #7

Open
billdenney opened this issue Sep 13, 2016 · 2 comments
Open

Have naturalorder consider decimals and scientific notation #7

billdenney opened this issue Sep 13, 2016 · 2 comments

Comments

@billdenney
Copy link

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
Copy link
Owner

kos59125 commented Sep 20, 2016

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
Copy link
Author

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

  • "natural": 2 3 1
  • "integer": 2 3 1
    • Same tokenization as "natural" in this case
  • "real": 2 3 1
    • Note that the tokenization of each string would have been different than natural here, but the result happens to be the same:
      • 1.0, ".", 1
      • 1.1, ".", 0
      • 1.0
  • "scientific": 2 3 1
    • Same tokenization as "real" in this case

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

  • "natural": 3 4 1 2
  • "integer": 2 4 1 3
    • Tokenization:
      • 1, ".", 0, -1
      • 1, ".", 1, -0 (interpreted as just 0)
      • 1, ".", 0
      • 1, ".", 0, -0
  • "real": 2 4 1 3
    • Tokenization:
      • 1.0, -1
      • 1.1, -0 (interpreted as just 0)
      • 1.0
      • 1.0, -0
  • "scientific": 2 4 1 3
    • Same tokenization as "real" in this case

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants