[R] simple question on glm

Marc Schwartz marc_schwartz at me.com
Thu Jun 18 23:50:58 CEST 2009


On Jun 18, 2009, at 4:36 PM, Jack Luo wrote:

> Hi,
>
> I am trying to use glm to fit my data, wondering if there is a easy  
> way to
> fit a glm without typing all the explanatory variable names. For  
> example, if
> I have 100 explanatory variables x1, x2, ..., x100 and response  
> variable is
> y, I don't want to do something like
> glm1 <- glm(y ~ x1 + x2 + ... + x100, family = gaussian, data = dataA)
> since it would be a lot of typing.
>
> Many thanks,
>
> -Jack

If y and x1 through x100 are the only variables in dataA, you can use:

   glm(y ~ ., data = dataA)

The '.' in the formula indicates that all variables not already in the  
formula should be used.

See ?formula for more information.

HTH,

Marc Schwartz




More information about the R-help mailing list