[R] Dots in models formulae

Gavin Simpson gavin.simpson at ucl.ac.uk
Tue Aug 16 19:17:51 CEST 2005


On Tue, 2005-08-16 at 18:43 +0200, Laurent Valdes wrote:
> I have seen, several times, dots (like this: "y ~." ) in formula  
> descriptions, noticeably in R help.
> 
> I am unable to see what it does correspond to.
> 
> Any ideas ?

The "." is a short cut to mean all variables specified in the data
argument. E.g.:

> dat <- data.frame(y = 1:10, x = 1:10, z = 1:10)
> model.frame(y ~ ., data = dat)
    y  x  z
1   1  1  1
2   2  2  2
3   3  3  3
4   4  4  4
5   5  5  5
6   6  6  6
7   7  7  7
8   8  8  8
9   9  9  9
10 10 10 10

If the response is also found on the rhs (right-hand-side) of the
formula (i.e via using ".") then it is silently droppped from the rhs.

So this is equivalent to the above formula

> model.frame(y ~ x + y + z, data = dat)
    y  x  z
1   1  1  1
2   2  2  2
3   3  3  3
4   4  4  4
5   5  5  5
6   6  6  6
7   7  7  7
8   8  8  8
9   9  9  9
10 10 10 10

Here y isn't the response but is included as it is in ".", i.e. dat.
> a <- 1:10
> model.frame(a ~ ., data = dat)
    a  y  x  z
1   1  1  1  1
2   2  2  2  2
3   3  3  3  3
4   4  4  4  4
5   5  5  5  5
6   6  6  6  6
7   7  7  7  7
8   8  8  8  8
9   9  9  9  9
10 10 10 10 10

If we don't specify data and we don't have an object named "." (which
may be impossible - I don't know) you get an error:

> model.frame(a ~ .)
Error in eval(expr, envir, enclos) : Object "." not found

I couldn't find "." documented for use in forumla (only for update(),
where it means something slightly different) but I remember seeing this
somewhere.

HTH

G
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson                     [T] +44 (0)20 7679 5522
ENSIS Research Fellow             [F] +44 (0)20 7679 7565
ENSIS Ltd. & ECRC                 [E] gavin.simpsonATNOSPAMucl.ac.uk
UCL Department of Geography       [W] http://www.ucl.ac.uk/~ucfagls/cv/
26 Bedford Way                    [W] http://www.ucl.ac.uk/~ucfagls/
London.  WC1H 0AP.
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%




More information about the R-help mailing list