[R] how to control the data type
Dirk Eddelbuettel
edd at debian.org
Fri Apr 21 05:18:27 CEST 2006
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
More information about the R-help
mailing list