0

In Python there is a way to make large numerals more readable using the underscore, e.g. 1000000 == 1_000_000, as discussed several times here. However, is there something similar in R?

Googling it just leads me to how to format the variable as a string using format and formatC. I already tried 1_000, 1 000, 1'000 and 1,000 but they only produce error messages. Is there really no workaround?

chickenNinja123
  • 311
  • 2
  • 11
  • 1
    Not to my knowledge... but a workaround would be to write number as string with _ or , and then use gsub to remove the _ or , as you parse them to numeric. – bricx Nov 19 '21 at 16:43
  • Thanks, that's a nice hack! – chickenNinja123 Nov 19 '21 at 16:44
  • I believe this is the very reason people use scientific notation. Why not just use `10e6` ? – GuedesBF Nov 19 '21 at 17:35
  • Here is discussion on the R mailing list about the implementation of this feature: https://stat.ethz.ch/pipermail/r-devel/2022-July/081874.html – nukubiho Aug 17 '22 at 19:40

1 Answers1

1

Something like this:

as.numeric(gsub("_","", "1_000_000"))
bricx
  • 593
  • 4
  • 18