Hello, I am using the following script to run an anova for numerous species in a table that I have: SiteSpp <- c("ADHALP","ADLCON","ADLARC","BDALAT","BDPARC","BDLCON","BDLARC","AWCAQU","AWERUS","AWEANG","AWDPSI","BWCSTA","BWHPAU","BWETRI","BWERUS","BWDFIS","BWPARC","BWLCON","BWLARC","BWJBIG") n.SiteSpp <- length(SiteSpp) for (i in (1:n.SiteSpp)) { QInfl.aov <- aov(AvgOfnumResponse ~ strTrea*strYear, data=QInflAvgbyPlot, subset=(SiteSpp == SiteSpp[i])) print(summary(QInfl.aov)) } The resulting summary just continuously prints the same anova results (For ADHALP) over and over again.... Any suggestions? Thanks, Kelsey -- View this message in context: http://r.789695.n4.nabble.com/For-loop-for-subset-repeating-same-over-and-over-tp3858115p3858115.html Sent from the R help mailing list archive at Nabble.com.
The first suggestion would be to use dput() to allow people on here to access your data. see ?dput I think you will want to post the output from: dput(QInflAvgbyPlot) ## or whatever object contains your data kelseyann wrote:> > Hello, I am using the following script to run an anova for numerous > species in a table that I have: > > > SiteSpp <- > c("ADHALP","ADLCON","ADLARC","BDALAT","BDPARC","BDLCON","BDLARC","AWCAQU","AWERUS","AWEANG","AWDPSI","BWCSTA","BWHPAU","BWETRI","BWERUS","BWDFIS","BWPARC","BWLCON","BWLARC","BWJBIG") > > n.SiteSpp <- length(SiteSpp) > > for (i in (1:n.SiteSpp)) { > QInfl.aov <- aov(AvgOfnumResponse ~ strTrea*strYear, > data=QInflAvgbyPlot, subset=(SiteSpp == SiteSpp[i])) > print(summary(QInfl.aov)) > } > > > The resulting summary just continuously prints the same anova results (For > ADHALP) over and over again.... Any suggestions? > > Thanks, > Kelsey >-- View this message in context: http://r.789695.n4.nabble.com/For-loop-for-subset-repeating-same-over-and-over-tp3858115p3858421.html Sent from the R help mailing list archive at Nabble.com.
Not reproducible. Could you please attach the dataset QInflAvgbyPlot Otherwise I don't see anything obviously wrong here. Ciao! mario On 30-Sep-11 01:37, kelseyann wrote:> SiteSpp<- > c("ADHALP","ADLCON","ADLARC","BDALAT","BDPARC","BDLCON","BDLARC","AWCAQU","AWERUS","AWEANG","AWDPSI","BWCSTA","BWHPAU","BWETRI","BWERUS","BWDFIS","BWPARC","BWLCON","BWLARC","BWJBIG") > > n.SiteSpp<- length(SiteSpp) > > for (i in (1:n.SiteSpp)) { > QInfl.aov<- aov(AvgOfnumResponse ~ strTrea*strYear, > data=QInflAvgbyPlot, subset=(SiteSpp == SiteSpp[i])) > print(summary(QInfl.aov)) > }-- Ing. Mario Valle Data Analysis and Visualization Group | http://www.cscs.ch/~mvalle Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82
Dennis Murphy
2011-Sep-30 10:14 UTC
[R] For loop for subset - repeating same over and over?
Hi: This would be a lot easier to check with a reproducible example, but here's a simplified version of your problem: testd <- data.frame(gps = rep(c("ADHALP","ADLCON","ADLARC","BDALAT","BDPARC"), each = 15), trt = rep(LETTERS[1:3], each = 5), y = rnorm(75)) testd$gps <- as.character(testd$gps) str(testd) library('plyr') # The subset is handled by the grouping variable gps: mlist <- dlply(testd, .(gps), function(d) aov(y ~ trt, data = d)) # Apply the summary function to each groupwise ANOVA: llply(mlist, summary) # Equivalent approach: # splitting the data by gps is equivalent to use of the grouping variable in dlply() mlist2 <- lapply(split(testd, testd$gps), function(d) aov(y ~ trt, data = d)) llply(mlist2, summary) Is that what you had in mind? Dennis On Thu, Sep 29, 2011 at 4:37 PM, kelseyann <kremerke at mail.gvsu.edu> wrote:> Hello, I am using the following script to run an anova for numerous species > in a table that I have: > > > SiteSpp <- > c("ADHALP","ADLCON","ADLARC","BDALAT","BDPARC","BDLCON","BDLARC","AWCAQU","AWERUS","AWEANG","AWDPSI","BWCSTA","BWHPAU","BWETRI","BWERUS","BWDFIS","BWPARC","BWLCON","BWLARC","BWJBIG") > > n.SiteSpp <- length(SiteSpp) > > ?for (i in (1:n.SiteSpp)) { > ? ? ?QInfl.aov <- aov(AvgOfnumResponse ~ strTrea*strYear, > data=QInflAvgbyPlot, subset=(SiteSpp == SiteSpp[i])) > ? ? ?print(summary(QInfl.aov)) > ?} > > > The resulting summary just continuously prints the same anova results (For > ADHALP) over and over again.... Any suggestions? > > Thanks, > Kelsey > > -- > View this message in context: http://r.789695.n4.nabble.com/For-loop-for-subset-repeating-same-over-and-over-tp3858115p3858115.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >