[R] Specification of model formulae
kjetil@entelnet.bo
kjetil at entelnet.bo
Fri Apr 16 17:50:32 CEST 2004
On 16 Apr 2004 at 17:08, Christian Hennig wrote:
You can build your formula along the ways of the following example,
without typing the 200 names:
> nam <- paste("var", 1:5, sep="", collapse="+")
> nam
[1] "var1+var2+var3+var4+var5"
> nam <- paste("y", nam, sep="~")
> nam
[1] "y~var1+var2+var3+var4+var5"
> as.formula(nam)
y ~ var1 + var2 + var3 + var4 + var5
Kjetil Halvorsen
> Hi,
>
> is it true that the only way to tell rpart which variables to use is
> to specify every single variable in the formula and separate them with
> "+"?
>
> I wonder if this error...
>
> > rotree <- rpart(powerdata[,1]~powerdata[,2:3],
> + method="class")
> Error in model.frame(formula, rownames, variables, varnames, extras,
> extranames, :
> invalid variable type
>
> ...can be prevented by other means than...
>
> > rotree <- rpart(segments~V1.3+V1.9,
> + method="class",data=powerdata)
>
> This works.
> (The variables here are powerdata[,1] and [,2:3].)
>
> But I do not want to write 200 variable names down, as this is the
> real size of "powerdata".
>
> Is there any way around that?
>
> Christian
>
>
>
> **********************************************************************
> * Christian Hennig Fachbereich Mathematik-SPST/ZMS, Universitaet
> Hamburg hennig at math.uni-hamburg.de,
> http://www.math.uni-hamburg.de/home/hennig/
> ######################################################################
> # ich empfehle www.boag-online.de
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list