# [R] numeric(0)

Peter Dalgaard p.dalgaard at biostat.ku.dk
Wed Dec 29 18:46:33 CET 2004

```(Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> writes:

> A:  Unary -
> B:  ^
> C:  :
> D:  * /
> E:  + -
>
> The position of ":" in this surprises me, intuitively.
> I can see reasons why it would be natural for ":" to come
> below "Unary -" -- this makes sense of the natural "-2:2",
> for instance, so that this gives "-2 -1 0 1 2" and not "-2".
>
> However, I don't see why it was chosen to make "1:2^4" mean
> "1:(2^4)" and not "(1:2)^4". My intuitive expectation is that
> this should follow the pattern of 1:2*4 or 1:2+4. All three
> are, after all, simply binary arithmetic operators. So I'd
> have expected to find ":" at position "B", above "^" at "C",
> and not between "^" and "*".

Well, ^ traditionally has higher precedence than unary - (-2^4 is -16)
and as you just argued, - has higher precedence than :, so by
transitivity...

Apart from that, you may want to consider model formulas like a:(b+c+d)^2

> What's the best place to look for the details on operator
> precedence and the like in R?

?Syntax has it, and ?Arithmetic points you there. The true authority
is gram.y in the sources (in the sense that it defines what happens,
not just says what ought to happen).

--
O__  ---- Peter Dalgaard             Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics     2200 Cph. N
(*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907

```