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

From: Nathaniel Smith <njs_at_pobox.com>
Date: Sat, 05 Jun 2010 13:30:54 -0700


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?


R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 05 Jun 2010 - 20:35:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 05 Jun 2010 - 21:10:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive