Skip to content
Prev 389421 / 398503 Next

How to use ifelse without invoking warnings

Dear Ravi,

It's already been suggested that you could disable warnings, but that's 
risky in case there's a warning that you didn't anticipate. Here's a 
different approach:

 > kk <- k[k >= -1 & k <= n]
 > ans <- numeric(length(k))
 > ans[k > n] <- 1
 > ans[k >= -1 & k <= n] <- pbeta(p, kk + 1, n - kk, lower.tail=FALSE)
 > ans
[1] 0.000000000 0.006821826 0.254991551 1.000000000

BTW, I don't think that you mentioned that p = 0.3, but that seems 
apparent from the output you showed.

I hope this helps,
  John
Message-ID: <6203fea2-3235-531d-891f-01a0ac23bef7@mcmaster.ca>
In-Reply-To: <8197_1633627307_197HLkf0027632_MW4PR01MB6212AE658D3DDB1A55B38469F2B19@MW4PR01MB6212.prod.exchangelabs.com>