[R] Pass an operator to function
David Winsemius
dwinsemius at comcast.net
Wed Dec 1 05:17:28 CET 2010
On Nov 30, 2010, at 9:54 PM, randomcz wrote:
>
> Hi guys,
>
> How to pass an operator to a function. For example,
>
> test <- function(a, ">", b)
> {
> return(a>b) #the operator is passed as an argument
> }
I think you have just requested the definition of do.call() although
you infix positioning is a bit non-standard:
?do.call
> do_this <- function(a, fn=">", b) {do.call(fn, list(a , b))}
> do_this(a=1, b=4)
[1] FALSE
> do_this(a=1, b=0)
[1] TRUE
>
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list