[R] The curious special case of "~ (a + b)/c"

Nathaniel Smith njs at pobox.com
Sat Jun 5 22:30:54 CEST 2010


This isn't at all an urgent practical question, but recently while
exploring the details of how R formulas are interpreted, I learned of
this funny special case for how / interacts with +. In all of the
following cases, the multiplication-like operator simply distributes
over addition:
  (a + b):c = a:c + a:c
  a:(b + c) = a:b + a:c
  (a + b)*c = a*c + b*c
  a*(b + c) = a*b + a*c
  a/(b + c) = a/b + a/c

But:
  (a + b)/c = a + b + a:b:c, not a/c + b/c = a + a:c + b + b:c

Chambers and Hastie mention this, but give no explanation (page 29/30,
"Slightly more subtle is...").

So for my own edification, does anyone know/care to speculate about
why (a + b)/c works this way?

-- Nathaniel



More information about the R-help mailing list