Re: [R] how to generate argument from a vector automatically

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Tue 12 Jul 2005 - 20:49:33 EST

zhihua li wrote:

> hi netters
>
> i have a vector NAMES containing a series of variable names:
> NAMES=c(x,r,z,m,st,qr,.....nn).
> i wanna fit a regression tree by using the code:
> my.tree<-tree(y~x+r+z+m+....nn,my.dataframe)
>
> but i don't want to type out "x+r+z+m+....+nn" one by one, as there are
> so many variables. besides, sometimes i wanna put the code in a
> function. so i need to have the argument "x+r+z+m+....+nn" generated
> from NAMES automatically.
>
> i've tried the code: paste(X,collpase="+") but it didn't work.

You have to construct it as.formula() from these characters, or even better use short term formulas such as "y~.", if all variables should be used anyway.

Uwe Ligges

> could anybody give me a hint?
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jul 12 20:51:02 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:32 EST