5

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
  • 32,567
  • 20
  • 113
  • 146
Walker in the City
  • 527
  • 1
  • 9
  • 22

2 Answers2

7

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
  • 42,459
  • 4
  • 77
  • 117
5

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

Tung
  • 26,371
  • 7
  • 91
  • 115