[R] how to control the data type

Pontarelli, Brett bpontar at amazon.com
Fri Apr 21 22:46:23 CEST 2006

You can also try:



-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Dirk Eddelbuettel
Sent: Thursday, April 20, 2006 8:18 PM
To: zhongmiao wang
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] how to control the data type

On 20 April 2006 at 22:00, zhongmiao wang wrote:
| Hello:
| I am generating a random number with rnorm(1). The generated number 
| has 8 decimals. I don't want so many decimals. How to control the 
| number of decimals in R?

You must have installed the professional version of R, just downgrade to the home version which has only four digits precision.

Seriously, your equating display precision with the representation -- which is not correct.  Consider:

> a <- 1/3
> print(a)
[1] 0.3333333
> print(a, digits=18)
[1] 0.333333333333333315

where the second print statement forces a display beyond the number of
significant digits.   So with that, your rnorm(1) result will also have more
than the eight digits you saw earlier:

> print(rnorm(1), digits=18)
[1] -0.201840514213267291

Hope this helps,  Dirk

Hell, there are no rules here - we're trying to accomplish something. 
                                                  -- Thomas A. Edison

R-help at stat.math.ethz.ch mailing list
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

More information about the R-help mailing list