Formating numbers

Hi there! I'm a total newbie with R, but i;m doing my best to be better. I;m pretty sure this question is quite dumb, but i;m not sure about how to look for this answer by myself.

So i have a column that shows numbers like this:

[1] 1.22e+09 8.80e+08 8.06e+08 1.18e+09 1.12e+09 1.18e+09 5.77e+08

How can i replace my column for the complete values? I would like to have 1220000000 instead of 1.22e+09?

Thank you!

I don't know of any way to do that without also changing the numbers into text. If that is acceptable, here are some examples.

x <- 1200000000
x
#> [1] 1.2e+09
format(x, scientific = FALSE)
#> [1] "1200000000"
format(x, scientific = FALSE, big.mark = ",")
#> [1] "1,200,000,000"

Created on 2020-05-20 by the reprex package (v0.3.0)

If you cannot use text, please explain what you are trying to accomplish.

1 Like

This shows exactly what i need, but i would like to have numbers.

#> [1] 1.2e+09
format(x, scientific = FALSE)
#> [1] "1200000000"

I want to change numbers format only becouse i'm not used to work with this format..
If there is no simple way to do it, I could just get used to it, it's not a big deal.

Thank you for your answer!

You can control display of scientific notation with options(scipen = value) where value is the penalty. Positive values will give preference to fixed notation whereas negative values will give preference to scientific notation.

x <- 1200000000
print(x)
#> [1] 1.2e+09

getOption("scipen")
#> [1] 0

options(scipen = 10)
print(x)
#> [1] 1200000000

Created on 2020-05-21 by the reprex package (v0.3.0)

By setting scipen to a high value, you can practically guarantee fixed notation when working with large numbers.

1 Like

Thank you so much! That was exactly what i needed.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.