What are you doing at iteration 520 with the objects corresponding to the i + 1 index? And there's a reason why you get one value for tmp1 and tmp2 - you replace their values every iteration. Maybe you want tmp1[i] and tmp2[i]?
If this is not a recursive calculation, you could easily replace the loop with vectorized calculations, leaving you with cleaner code and, quite possibly, faster execution speed. HTH, Dennis On Mon, Sep 20, 2010 at 11:41 PM, andre bedon <andresa...@hotmail.com>wrote: > > Hi guys, > > Im new to R and am having a bit of trouble with what should be a simple > loop. It sprobably something very fundamental that im doing wrong. > > > > for(i in c(1:520)) > { > tmp1<- ((1-samp.pct[i])^2)*(log(1-theor.pct[i])-log(1-theor.pct[i+1])) > tmp2<- ((samp.pct[i])^2)*(log(theor.pct[i+1])-log(theor.pct[i])) > } > ADtest.stat<- (-n*(max(theor.pct))) + (n*sum(tmp1)) + (n*sum(tmp2)) > names(ADtest.stat) <- c("Anderson-Darling test statistic") > print(ADtest.stat) > > > > samp.pct is a vector containing 520 values between 0 and 1, so is > theor.pct. n is 520. > > After running this code, tmp1 and tmp2 return only one value, where I need > around 520 values. Any ideas would be appreciated. > > > > Regards, > > > > Andre > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.