[R] Pass an operator to function

sachinthaka.abeywardana at allianz.com.au sachinthaka.abeywardana at allianz.com.au
Wed Dec 1 06:39:42 CET 2010


If you only want to deal with the less than or greater than operation a
cheap trick would be:

test <- function(a, b, sign) {
  foo <- (a*sign > b*sign);
  return(foo);
}

might have to tweak the syntax.

The idea behind this is that
5>3: TRUE
-5>-3: FALSE (i.e. I've multiplied both sides by sign(-1))

Hope this helps,
Sachin
p.s. sorry about corporate notice.

--- Please consider the environment before printing this email --- 

Allianz - Best General Insurance Company of the Year 2010*
Allianz - General Insurance Company of the Year 2009+ 

* Australian Banking and Finance Insurance Awards
+ Australia and New Zealand Insurance Industry Awards 

This email and any attachments has been sent by Allianz ...{{dropped:3}}



More information about the R-help mailing list