You can also try: round(runif(1)*10^4)/10^4
--Brett -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dirk Eddelbuettel Sent: Thursday, April 20, 2006 8:18 PM To: zhongmiao wang Cc: [email protected] 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 ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
