[R] Spaces in a name

Gabor Grothendieck ggrothendieck at gmail.com
Wed Jul 15 20:33:35 CEST 2009


Try this with built in BOD:

> names(BOD) <- paste(names(BOD), "X")
> BOD
  Time X demand X
1      1      8.3
2      2     10.3
3      3     19.0
4      4     16.0
5      5     15.6
6      7     19.8
> lm(`demand X` ~ `Time X`, BOD)

Call:
lm(formula = `demand X` ~ `Time X`, data = BOD)

Coefficients:
(Intercept)     `Time X`
      8.521        1.721

>


On Wed, Jul 15, 2009 at 10:40 AM, Idgarad<idgarad at gmail.com> wrote:
> I am reading regressors from an excel file (I have no control over the file)
> and some of the element names have spaces:
>
> i.e. "Small Bank Aquired"
>
> but I have found that lm(SourceData ~ . - "Small Bank Aquired", mcReg)
> doesn't work (mcReg = modelCurrentRegressors)
>
> As they are toggles I have ran them through factor() to be treated propertly
> as 0 or 1 but due to the fact I am grabbing automagically the first 2/3rds
> of the data some of the regressors are either all 0s or all 1s accordingly
> so I need to take them out of the model by hand for now until I find a nice
> automatic method for removing regressors that only have 1 factor.
>
> So Primarily: how do I handle names that include spaces in this context and
> as a bonus: Anyone have a nice method for yanking regressors that only have
> a single factor in them from the lm() function?
>
>
> e.g. (for the following 30 elements)
> 0,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,0,0,
> 1,1,1,1,1,1,1,1,1,1
>
> As you can see grabbing the first 2/3rds is all 0s and the last 1/3rd is all
> ones (doing in-sample forecast diagnostic building the model only on the
> first 2/3rds of data, then forecasting the next 1/3rd and comparing.)
>
> Sorry if I am rambling a bit, still on cup of coffee #1...
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>




More information about the R-help mailing list