Prevent as.character from using exponential notation r [duplicate]
Asked Answered
F

2

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!

Fe answered 12/2, 2018 at 23:1 Comment(1)
This is almost surely a options(scipen...) rather than a formatting issueElusive
J
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"
Jacky answered 12/2, 2018 at 23:3 Comment(0)
L
5

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

Lancashire answered 13/2, 2018 at 0:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.