[R] Pulling data into a model

Luc Villandre villandl at dms.umontreal.ca
Wed Apr 8 16:09:57 CEST 2009


Hi Jacy,

I'll take my chances answering your question.

I'd suggest using the paste() function and then transforming the string 
into a formula object:


my.formula = 
as.formula(paste("y~x1+x2+",paste(colnames(REG)[2:num],collapse="+"), 
sep= "")) ;

aov(my.formula,data=REG) ;


The first line creates a string that then becomes your formula statement.

Is this what you're looking for?

Cheers,

Luc

Crosby, Jacy R wrote:
> I'm creating an ANOVA model. Is there a way to pull in consecutive columns of variables for the test?
>
> Example:  aov1<-aov(y~x1+x2+REG[,2:num], data=REG)
>
> I'm not looking for interaction effects, I just want to create a model for the first few columns of variables (exact number and names will vary) and a few other predetermined variables (in the example I named them x1 and x2).
>
> Thanks in advance.
> - Jacy
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list