Re: [R] thousands separator in console output?

2009-11-11 Thread Marc Schwartz

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

Hello, I'm beginning with R and I'm wondering if there's any way to  
display
large values (e.g. 161651654167) using my system's thousands  
separator or

scientific notation.

Thanks!


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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] thousands separator in console output?

2009-11-11 Thread Patricio Cuarón
Hello, I'm beginning with R and I'm wondering if there's any way to display
large values (e.g. 161651654167) using my system's thousands separator or
scientific notation.

Thanks!

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.