Completely remove scientific notation for the entire R session

I do not want to see any scientific notation in any result of any calculation in my session R. I want to see all the actual numbers, preferably with a comma (,) after every three digits.

How can i do this? options(scipen = 999) does not cut.

+7
source share
1 answer

The print.default function looks at the value of options()['digits'] in the “solution”, what width it allocates, so you may need to increase it, as well as try to maximize “scipen”. There are special OS problems with values ​​above 16 for this width. As for the comma request ... forget about it. R is not a financial reporting system. If you need to force this output format, you can define objects of a certain class and write print methods for them using sprintf and formatC, or, I suppose, you can rewrite print.default, but this can only affect print operations that do not were passed to one of the other 100+ methods for print .

There are output methods. formatC() and prettyNum() both have an argument of "big.mark" that inserts commas into numbers. The output is in the "character" format, so do not try to do further calculations on the generated results.

There are also input methods that can read columns with numbers containing commas or currency symbols:

 setAs("character", "num.with.commas", function(from) as.numeric(gsub(",", "", from))) setAs("character", "euro", function(from) as.numeric(gsub("€", "", from))) setAs("character", "num_pct", function(from) as.numeric(gsub("%", "", from))/100) # you will get warning messages if you have not defined the class, # .... but this will still succeed Input <- "ABC 1,000 1% 3.50€ 2,000 2% 4.77€ 3,000 3% €5.68 " DF <- read.table(textConnection(Input), header = TRUE, colClasses = c("num.with.commas", "num_pct", "euro")) str(DF) 
+10
source

All Articles