[R] For loop for subset - repeating same over and over?
peter dalgaard
pdalgd at gmail.com
Fri Sep 30 11:02:31 CEST 2011
On Sep 30, 2011, at 08:32 , Mario Valle wrote:
> 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]))
This looks like the culprit. I suppose there is a SiteSpp in the data set too. There's no way that you could have two different SiteSpp on the two sides of "==", so try renaming the one in the global environment. Or redo the loop as
for (x in SiteSpp)
.... subset=(SiteSpp==x))
(_and_, for your own long-term sanity, rename SiteSpp as well)
>> 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
>
> ______________________________________________
> 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.
--
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list