[R] variables as arguments in formulae in aov?
ggrothendieck at gmail.com
Tue Mar 28 18:14:46 CEST 2006
Try something like this:
for(i in 1:4) print(summary(lm(iris[,i] ~., iris[,-i])))
for(i in 1:4) print(lm(y ~ Species, data.frame(y = iris[,i], Species =
On 3/28/06, Colm Connolly <colmconn at gmail.com> wrote:
> Hi all,
> I wonder if you could help me with (what is surely) a simple R question?
> I've written a simple R script (attached) to perform multiple ANOVAs
> on the columns in a table loaded in from a a file (also attached). I
> loop through the list of columns for which I want to perform the
> ANOVAs, storing the column name in a variable. When I try to perform
> the ANOVA using the variable name as a reference to the column name R
> complains as follows:
> Error in the model.frame(formula, rownames, variables, varnames,
> extras, extranames, :
> invalid variable type
> The line causing the problem is the first line inside the for loop.
> The question is what have I done wrong? Is there a better way of doing
> the ANOVAs?
> Thanks in advance,
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help