Skip to content

thousands separator in console output?

2 messages · Patricio Cuarón, Marc Schwartz

#
On Nov 11, 2009, at 3:52 PM, Patricio Cuar?n wrote:

            
To get scientific notation as a default for given large values, see ? 
options and note 'scipen', which by default is 0.

 > 161651654167
[1] 161651654167

options(scipen = -5)

 > 161651654167
[1] 1.616517e+11

That is about the only way, by default, to adjust the output of  
numeric values, for which R uses ?print.default. You can play with the  
value of scipen to get the behavior you wish for some definition of  
'large' numbers.

If you want to format large numbers with commas as the thousand  
separator, that will not happen by default, but you can use format()  
to do this when outputting numbers as you may need in a function and/ 
or for pretty printing in tables, etc.:

 > format(161651654167, big.mark = ",")
[1] "161,651,654,167"

Note that the result is a character vector and not numeric.

See ?format and perhaps ?formatC for more information.

HTH,

Marc Schwartz