[R] wildcard operator

Erik Iverson eriki at ccbr.umn.edu
Thu May 27 07:03:42 CEST 2010

Eric Fail wrote:
> Hi Ruser
> As so usual I'm trying to replicate some SAS code. I wold like to know 
> if there is a wildcard operators, as  " : " in SAS, in R?
> When running:
> lm(y ~ x1 + x2 + x3 + x4 + x5 + x6 .... x9860, data=mydata)
> I would like to be able to get around it by just writing something like 
> this:
> lm(y ~ x1:x9860, data=mydata)

See ?formula, specifically:

      There are two special interpretations of ‘.’ in a formula.  The
      usual one is in the context of a ‘data’ argument of model fitting
      functions and means ‘all columns not otherwise in the formula’:
      see ‘terms.formula’.  In the context of ‘update.formula’, *only*,
      it means ‘what was previously in this part of the formula’.

So assuming all those RHS variables + y make up your data.frame

lm(y ~ ., data = mydata) would be fine.  You can easily create such a data.frame 
if you don't already have it using regexs.


More information about the R-help mailing list