Re: [R] beginner's question: group of regressors by name vector?

2009-02-12 Thread Gabor Grothendieck
If DF is a data frame with the variables, try this:

lm(l ~. , DF[c("l", "b", "j", "x"))


On Thu, Feb 12, 2009 at 11:11 AM,   wrote:
> dear r-experts: there is probably a very easy way to do it, but it eludes
> me right now. I have a large data frame with, say, 26 columns named "a"
> through "z". I would like to define "sets of regressors" from this data
> frame. something like
>
> myregressors=c("b", "j", "x")
> lm( l ~ myregressors, data=... )
>
> is the best way to create new data frames that contain all the variables I
> want, then use ".", and then destroy them again? or am I overlooking
> something obvious?
>
> sincerely,
>
> /iaw
>
>[[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] beginner's question: group of regressors by name vector?

2009-02-12 Thread David Freedman

The predictors and outcomes in lm can be matrices, so you could use something
like the following:
 
x.mat=cbind(x1=rnorm(20),x2=rnorm(20))
y.mat=cbind(y1=rnorm(20),y2=rnorm(20))
lm(y.mat~x.mat)

David Freedman

ivowel wrote:
> 
> dear r-experts: there is probably a very easy way to do it, but it eludes  
> me right now. I have a large data frame with, say, 26 columns named "a"  
> through "z". I would like to define "sets of regressors" from this data  
> frame. something like
> 
> myregressors=c("b", "j", "x")
> lm( l ~ myregressors, data=... )
> 
> is the best way to create new data frames that contain all the variables I  
> want, then use ".", and then destroy them again? or am I overlooking  
> something obvious?
> 
> sincerely,
> 
> /iaw
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/beginner%27s-question%3A-group-of-regressors-by-name-vector--tp21979180p21979495.html
Sent from the R help mailing list archive at Nabble.com.

__
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] beginner's question: group of regressors by name vector?

2009-02-12 Thread Gabor Grothendieck
Missed a bracket:

lm(l ~. , DF[c("l", "b", "j", "x")])

On Thu, Feb 12, 2009 at 11:21 AM, Gabor Grothendieck
 wrote:
> If DF is a data frame with the variables, try this:
>
> lm(l ~. , DF[c("l", "b", "j", "x"))
>
>
> On Thu, Feb 12, 2009 at 11:11 AM,   wrote:
>> dear r-experts: there is probably a very easy way to do it, but it eludes
>> me right now. I have a large data frame with, say, 26 columns named "a"
>> through "z". I would like to define "sets of regressors" from this data
>> frame. something like
>>
>> myregressors=c("b", "j", "x")
>> lm( l ~ myregressors, data=... )
>>
>> is the best way to create new data frames that contain all the variables I
>> want, then use ".", and then destroy them again? or am I overlooking
>> something obvious?
>>
>> sincerely,
>>
>> /iaw
>>
>>[[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.


[R] beginner's question: group of regressors by name vector?

2009-02-12 Thread ivowel
dear r-experts: there is probably a very easy way to do it, but it eludes  
me right now. I have a large data frame with, say, 26 columns named "a"  
through "z". I would like to define "sets of regressors" from this data  
frame. something like

myregressors=c("b", "j", "x")
lm( l ~ myregressors, data=... )

is the best way to create new data frames that contain all the variables I  
want, then use ".", and then destroy them again? or am I overlooking  
something obvious?

sincerely,

/iaw

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