[R] Question on meaning of '%+%', '%?%' (? = various single letter) in code

peter dalgaard pdalgd at gmail.com
Fri Jun 1 09:32:51 CEST 2012


On Jun 1, 2012, at 00:30 , Mike Hilt wrote:

> 
> Could someone help me out and let me know what ‘%?%’
> (where ? = a single letter in a 3 character string with ‘%’
> being the 1st and 3rd characters), and/or ‘%+%’ does in
> R code/function?

They are just a vehicle for defining binary operators: functions of two variables but called using infix notation. 

a %foo% b is equivalent to `%foo%`(a,b) just like 2 + 2 is

> `+`(2,2)
[1] 4

Like any other function, they do whatever you define them to do, but some are predefined, notably %*% (matrix multiply), %/%, %% (integer divide and remainder), and some packages add their own operators like %+%.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list