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) Anyone? Sorry for no including a working example, but I figured that it wasn't necessary. Thanks Eric
Hi Eric, Try lm(y ~ . , data = mydata) HTH, Jorge On Thu, May 27, 2010 at 12:58 AM, 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) > > Anyone? > > Sorry for no including a working example, but I figured that it wasn't > necessary. > > Thanks > > Eric > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
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. --Erik
Hi: On the off chance that your 9860 explanatory variables do not completely take up the 'non-y' part of your data frame, you can always write a formula string to pass to the model function. For example, form <- paste('y ~ ', paste('x', 1:10, sep = '', collapse = ' + '))> form[1] "y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10" m <- lm(form, data = df) HTH, Dennis On Wed, May 26, 2010 at 9:58 PM, Eric Fail <e@it.dk> 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) > > Anyone? > > Sorry for no including a working example, but I figured that it wasn't > necessary. > > Thanks > > Eric > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Seemingly Similar Threads
- creating 3-way tables for mantelhaen.test
- subset using noncontiguous variables by name (not index)
- help please ..simple question regarding output the p-value inside a function and lm
- Help with programming a tricky algorithm
- How to do the same thing for all levels of a column?