Table of Contents
To turn off scientific notation in R and display numbers as decimal values, you can use the function options(scipen = 999) to set the value of the scipen option to a large number. This will prevent R from automatically formatting numbers in scientific notation. Alternatively, you can use the format() function to specify the number of decimal places you want to display. For example, format(x, digits = 4) will display the number x with four decimal places. This will allow you to present your data in a more user-friendly and readable format.
Turn Off Scientific Notation in R (With Examples)
You can use the following methods to turn off scientific notation in R;
Method 1: Turn off scientific notation as global setting
options(scipen=999)
Method 2: Turn off scientific notation for one variable
format(x, scientific = F)
The following examples show how to use each of these methods in practice.
Method 1: Turn Off Scientific Notation as Global Setting
Suppose we perform the following multiplication in R:
#perform multiplication x <- 9999999 * 12345 #view resultsx [1] 1.2345e+11
The output is shown in scientific notation since the number is so large.
The following code shows how to turn off scientific notation as a global setting. This means no variable in any output will be shown in scientific notation.
#turn off scientific notation for all variables options(scipen=999) #perform multiplication x <- 9999999 * 12345 #view results x [1] 123449987655
Notice that the entire number is displayed since we turned off scientific notation.
Note that the default value for scipen is 0 so you can reset this global setting by using options(scipen=0) in R:
#turn scientific notation back on
options(scipen=0)
#perform multiplication again
x <- 9999999 * 12345
#view results
x
[1] 1.2345e+11
Method 2: Turn Off Scientific Notation for One Variable
The following code shows how to turn off scientific notation for just one variable:
#perform multiplication x <- 9999999 * 12345 #display results and turn of scientific notation format(x, scientific = F) [1] "123449987655" #perform another multiplication y <- 9999999 * 999999 #view results y [1] 9.999989e+12
Notice that only the first variable is shown without scientific notation since it’s the only variable that we used the format() function on.
The following tutorials show how to perform other common operations in R:
Cite this article
stats writer (2024). How can I turn off scientific notation in R and display numbers as decimal values?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-turn-off-scientific-notation-in-r-and-display-numbers-as-decimal-values/
stats writer. "How can I turn off scientific notation in R and display numbers as decimal values?." PSYCHOLOGICAL SCALES, 4 May. 2024, https://scales.arabpsychology.com/stats/how-can-i-turn-off-scientific-notation-in-r-and-display-numbers-as-decimal-values/.
stats writer. "How can I turn off scientific notation in R and display numbers as decimal values?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-turn-off-scientific-notation-in-r-and-display-numbers-as-decimal-values/.
stats writer (2024) 'How can I turn off scientific notation in R and display numbers as decimal values?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-turn-off-scientific-notation-in-r-and-display-numbers-as-decimal-values/.
[1] stats writer, "How can I turn off scientific notation in R and display numbers as decimal values?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, May, 2024.
stats writer. How can I turn off scientific notation in R and display numbers as decimal values?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
