Re: [R] Spaces in a name

2009-07-15 Thread Gabor Grothendieck
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.5211.721

>


On Wed, Jul 15, 2009 at 10:40 AM, Idgarad 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@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.
>

__
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.


Re: [R] Spaces in a name

2009-07-15 Thread Allan Engelhardt
Not sure how to get formula to handle spaces, but to get going you can 
just change the names in the data frame after you have read it, e.g.

names(mcReg) <- make.names(names(mcReg))

will (usually) give you Small.Bank.Acquired.

Allan

On 15/07/09 15:40, Idgarad 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@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]]

__
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.


[R] Spaces in a name

2009-07-15 Thread Idgarad
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@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.