[R] Check value interval in a if loop
Jim Lemon
jim at bitwrit.com.au
Sun Sep 27 22:41:45 CEST 2009
> Lucas Sevilla García wrote:
>> Hi R community
>>
>> I have a little problem, and I tried to solve it by myself but I
>> couldn't. I building an if loop, and I want to check a value inside
>> an interval. This would be the case:
>>
>> pvalue=0,2999
>>
>> if(pvalue>0.05 or pvalue<0.1)
>>
>> as you can see I would like to check in that if loop if my pvalue is
>> inside of that interval(from 0.05 to 0.1), and I tried these options:
Hi Lucas,
Your "if" statement is probably embedded in a loop like this:
for(mytest in 1:100) {
pvalue<-t.test(rnorm(50),rnorm(50))$p.value
if(pvalue > 0.05 && pvalue < 0.1) cat("Just missed!\n")
else cat("I don't care\n")
}
so you only want it to test the current p value. If you want to get all
the p values and test them later:
pvalue<-rep(NA,100)
for(mytest in 1:100)
pvalue[mytest]<-t.test(rnorm(50),rnorm(50))$p.value
cat(c("Just missed\n","I don't care\n")
[(pvalue > 0.05 & pvalue < 0.1)+1])
Jim
More information about the R-help
mailing list