[R] dot in formula

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jun 3 10:36:42 CEST 2005


On Fri, 3 Jun 2005, Bjørn-Helge Mevik wrote:

> Adrian Baddeley writes:
>
>> I want to manipulate a formula object, containing the name "."
>> so that "." is replaced by a desired (arbitrary) expression.
>
> How about
>
> myf <- y ~ .
> update(myf, . ~ -. + X)

or just update(myf, . ~ X).  Here "." is not being treated literally (nor 
can it be in the internal formula manipulation code).

If you just want to replace a rhs `.' then there are easier ways, e.g.

> myf <- y ~ .
> myf[[3]] <- quote(X)
> myf
y ~ X

However, I think Adrian might want something like

> myf <- y ~ a + . + x
> update(myf, . ~ -. + X)
y ~ X

I think the best way to do that is by substitute(), e.g.

> substitute(y ~ a + . + x, list("."=quote(X)))
y ~ a + X + x

If that is not enough ideas, perhaps Adrian could give us an example?

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list