[R] Long model formulae

David Winsemius dwinsemius at comcast.net
Sun Oct 24 07:32:15 CEST 2010


On Oct 23, 2010, at 6:56 PM, Gabor Grothendieck wrote:

> On Sat, Oct 23, 2010 at 9:51 PM, James Hirschorn
> <james.hirschorn at hotmail.com> wrote:
>>
>> What is a good way to enter a very long model formula. For example:
>>
>> y ~ Input.2 + Input.3 + ... + Input.1000
>>
>> (assuming the corresponding dataframe has many other columns).
>>
>> Is there a way to convert a character string to a formula? Are  
>> there command line expansions in R besides the simple '.'?
>>
>
> If y is in column 1 and Input.2, ..., Input.1000 are in columns 2
> through 1000 then try this:
>
>   lm(y ~., DF[1:1000])

I guess the next logical(?) question would be: If the independent  
variables of interest are in columns 3,5,6,7,8,9,10,and 13 and the  
dependent variable is in column 20, would this work:

lm(y ~., data=DF[c(20, 3,5,6:10, 13)])
# ? with any consecutive columns specified with the ":" operator?

Or perhaps with grep("patt") in with the column indices?

-- 
David.



More information about the R-help mailing list