Message-ID: <1354317888.56358.YahooMailNeo@web142605.mail.bf1.yahoo.com>
Date: 2012-11-30T23:24:48Z
From: arun
Subject: protentially serious R error
In-Reply-To: <1354309523616-4651495.post@n4.nabble.com>
HI,
Use either ?round() or ?signif()
?rnorm(signif(20*(1-0.8)))
#[1]? 1.58079490 -0.03595492 -0.11561782? 0.12951975
?rnorm(signif(20*0.2))
#[1]? 1.70722614? 0.40898103 -2.94663960 -0.09284011
A.K.
----- Original Message -----
From: liuxf <liuxf at math.mcmaster.ca>
To: r-help at r-project.org
Cc:
Sent: Friday, November 30, 2012 4:05 PM
Subject: [R] protentially serious R error
Hi guy,
I have recently encountered a problem while? I was just trying to generate
some random numbers with the function "rnorm", the problem is shown below:
########case 1############
> rnorm(20*0.2)
[1] -1.2765922 -0.5732654 -1.2246126 -0.4734006
########case 2###########
*> rnorm(20*(1-0.8))
[1] -0.62036668? 0.04211587 -0.91092165*
#########case 3############
> a<-0.2
> rnorm(20*a)
[1]? 0.1580288 -0.6545846? 1.7672873? 0.7167075
#############case 4#########
*> b<-1-0.8
> rnorm(20*b)
[1] 0.9101742 0.3841854 1.6821761*
I was expecting the 4 cases should do the same job--generate 4 random
numbers. But in case 2 and 4 I only get 3. Has anyone else seen this problem
before? Thanks. (I have tried with other functions i.e "rchisq","rexp" ...)
#######################################################################
One of my colleague also have a problem that we think it might be related
with the problem I addressed above:
> test1 <- runif(10,0,1)
> test1
[1] 0.3868379 0.1587814 0.8140483 0.7796691 0.5357628 0.2431110 0.1782747
0.3906829 0.5262615 0.7440143
> test2 <- NULL
> for(i in seq(0.01,1,length=100)){
+? test2[i*100] <- sum(test1<i)
+ }
> test2
? [1]? 0? 0? 0? 0? 0? 0 *NA*? 0? 0? 0? 0? 0? 0? 0? 0? 1? 1? 2? 2? 2? 2? 2? 2
2? 3? 3? 3? 3? 3? 3? 3? 3? 3? 3? 3? 3? 3? 3? 4? 5? 5? 5? 5? 5
[45]? 5? 5? 5? 5? 5? 5? 5? 5? 6? 7? 7? 7? 7? 7? 7? 7? 7? 7? 7? 7? 7? 7? 7
7? 7? 7? 7? 7? 7? 7? 8? 8? 8? 9? 9? 9? 9 10 10 10 10 10 10 10
[89] 10 10 10 10 10 10 10 10 10 10 10 10
Every time he re-runs the code there always always a "NA"(highlighted). Does
any one know why?? Your help is greatly appreciated.?
Xiaofeng
--
View this message in context: http://r.789695.n4.nabble.com/protentially-serious-R-error-tp4651495.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help at 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.