4

Is there a way to prevent as.character from using exponential notation? For example, I have

num <- c(9999999, 10000000)
char <- as.character(num)
char
[1] "9999999" "1e+07"

But instead I would like to have char be "9999999" "10000000". Thanks!

smci
  • 29,564
  • 18
  • 109
  • 144
Walker in the City
  • 487
  • 1
  • 7
  • 21

2 Answers2

5

format is the function that lets you choose how you want your numbers formatted when converting to character. In this case, something like

format(c(9999999, 10000000), scientific = FALSE, trim = TRUE)
#> [1] "9999999"  "10000000"
alistaire
  • 40,464
  • 4
  • 71
  • 108
4

You can also use options(scipen = 999) in the beginning of your R script to completely disable scientific notation

Tung
  • 23,290
  • 6
  • 81
  • 97