Dear Ravi,
I have uploaded on GitHub a version which handles also constant values
instead of functions.
Regarding named arguments: this is actually handled automatically as well:
eval.by.formula((x > 5 & x %% 2) ~ (x <= 5) ~ ., FUN, y=2, x)
# [1] 1 4 9 16 25 6 14 8 18 10
eval.by.formul
Dear Ravi,
I wrote a small replacement for ifelse() which avoids such unnecessary
evaluations (it bothered me a few times as well - so I decided to try a
small replacement).
### Example:
x = 1:10
FUN = list();
FUN[[1]] = function(x, y) x*y;
FUN[[2]] = function(x, y) x^2;
FUN[[3]] = function
(tmp <- yes; tmp[!test] <- no[!test]; tmp)
, possibly extended to handle missing values in 'test'.
Best,
-Deepayan
> Thanks & Best regards,
> Ravi
>
> From: John Fox
> Sent: Thursday, October 7, 2021 2:00 PM
> To
>to avoid this behavior.
>
>Thanks & Best regards,
>Ravi
>
>From: John Fox
>Sent: Thursday, October 7, 2021 2:00 PM
>To: Ravi Varadhan
>Cc: R-Help
>Subject: Re: [R] How to use ifelse without invoking warnings
>
>
>
i Varadhan via
R-help
Sent: Friday, October 8, 2021 8:22 AMiu
To: John Fox l
Cc: R-Help
Subject: Re: [R] How to use ifelse without invoking warnings
Thank you to Bert, Sarah, and John. I did consider suppressing warnings, but
I felt that there must be a more principled approach. While John'
regards,
Ravi
From: John Fox
Sent: Thursday, October 7, 2021 2:00 PM
To: Ravi Varadhan
Cc: R-Help
Subject: Re: [R] How to use ifelse without invoking warnings
External Email - Use Caution
Dear Ravi,
It's already been suggested that you could disable w
for large arguments.
Best,
John
Thanks & Best regards,
Ravi
*From:* John Fox
*Sent:* Thursday, October 7, 2021 2:00 PM
*To:* Ravi Varadhan
*Cc:* R-Help
*Subject:* Re: [R] How to use ifelse without inv
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 -
Bert's approach is much less risky!
On Thu, Oct 7, 2021 at 1:37 PM Bert Gunter wrote:
>
> ?suppressWarnings
>
> > p <- .05
> > k <- c(-1.2,-0.5, 1.5, 10.4)
> > n <- 10
> >
> > ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE),
> ifelse (k < -1, 0, 1) )
> Warning message:
> In pbe
If you are positive the warnings don't matter for your application,
you can disable them: see ?options for details of warn.
But that can be dangerous, so be careful!
Sarah
On Thu, Oct 7, 2021 at 1:21 PM Ravi Varadhan via R-help
wrote:
>
> Hi,
> I would like to execute the following vectorized c
?suppressWarnings
> p <- .05
> k <- c(-1.2,-0.5, 1.5, 10.4)
> n <- 10
>
> ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE),
ifelse (k < -1, 0, 1) )
Warning message:
In pbeta(p, k + 1, n - k, lower.tail = FALSE) : NaNs produced
>
> suppressWarnings(ans <- ifelse (k >= -1 & k <= n,
Hi,
I would like to execute the following vectorized calculation:
ans <- ifelse (k >= -1 & k <= n, pbeta(p, k+1, n-k, lower.tail = FALSE),
ifelse (k < -1, 0, 1) )
For example:
> k <- c(-1.2,-0.5, 1.5, 10.4)
> n <- 10
> ans <- ifelse (k >= -1 & k <= n, pbeta(p,k+1,n-k,lower.tail=FALSE), ifels
12 matches
Mail list logo