Marc Schwartz wrote:
> Esmail Bonakdarian wrote:
>
> Depending upon other factors, there may be a better and more general
> approach to what you are trying to do relative to selecting subsets of
> IV's. However, given the information you have provided:
>
> vars <- c('X.1', 'X.2', 'X.3', 'X.4', 'X.5')
> bits <- c(1, 0, 1, 1, 0)
>
> > paste(vars[bits == 1], collapse = " + ")
> [1] "X.1 + X.3 + X.4"
>
>
> bits <- c(1, 1, 0, 0, 0)
>
> > paste(vars[bits == 1], collapse = " + ")
> [1] "X.1 + X.2"
>
>
> You will then need to use as.formula() to coerce the resultant vectors
> before passing them to the model function.
One other tweak here, if you use TRUE/FALSE rather than 1/0 to define the positions and this gets rid of the need for 'vars':
bits <- c(TRUE, FALSE, TRUE, TRUE, FALSE)
> paste("X", which(bits), collapse = " + ", sep = ".") [1] "X.1 + X.3 + X.4"
HTH, Marc
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.