Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 961
Walker in the City Avatar asked Jan 02 '23 19:01

Walker in the City


1 Answers

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"
like image 91
alistaire Avatar answered Jan 05 '23 16:01

alistaire