1
 data(dune)
 data(dune.env)

 results<-list()
 for (i in colnames(dune.env)){
         results[[i]]<- adonis(dune ~ i, data=dune.env, permutations=99)
  }

When I test each name in colnames(dune.env), it can work. But it can not work in the loop function above. I think it is due to the i in the loop fuction has " ". How to fix it? Thanks.

Ming
  • 181
  • 2
  • 10

1 Answers1

6

I know nothing about adonis, but I do know that formulas are language objects which do not take nicely to being treated as though they were ordinary character objects.

for (i in colnames(dune.env)){ 
           form <- as.formula(paste("dune", i, sep="~"))
           results[[i]]<- adonis(form, data=dune.env, permutations=99)
           }   
IRTFM
  • 258,963
  • 21
  • 364
  • 487