Re: [R] building a formula string bit by bit ..

From: Esmail Bonakdarian <esmail.js_at_gmail.com>
Date: Tue, 06 May 2008 15:43:19 -0400

Jorge Ivan Velez wrote:
> Hi Esmail,
>
> Try this:
>
> vars=c('X.1', 'X.2', 'X.3', 'X.4', 'X.5')
> bits=c(1, 0, 1, 1, 0)
> paste(vars[which(bits==1)],collapse="+")
>
> HTH,
>
> Jorge

Wow .. that is beautiful :-) .. and exactly what I was looking for (and suspected existed).

I ended up doing this:

    eqn=(paste(vars[which(bits==1)],collapse=" + "))     eqn=paste(c("Y.data ~"), eqn)
    GLM.9 <- glm(as.formula(eqn) , family=gaussian(identity), data=simpleData)

For some reason I couldn't collapse the two eqn/paste statements into one statement but this seems to work.

Thank again Jorge and everyone else .. this group is a big help.

Esmail



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. Received on Tue 06 May 2008 - 19:49:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 06 May 2008 - 20:30:43 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive