防止 as.character 使用指数记数法 r

Prevent as.character from using exponential notation r

有没有办法阻止 as.character 使用指数表示法?例如,我有

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

但我希望 char 成为 "9999999" "10000000"。谢谢!

format 是让您选择在转换为字符时如何格式化数字的函数。在这种情况下,类似于

format(c(9999999, 10000000), scientific = FALSE, trim = TRUE)
#> [1] "9999999"  "10000000"

您还可以在 R 脚本的开头使用 options(scipen = 999) 来完全禁用科学记数法