Hi Hannah, No, we can't help because we have no idea what rho.f does - you didn't provide the requested reproducible example. Without more information, the only thing I can think of is that your function might be ridiculously sensive to numeric precision (though that seems unlikely):
> corr <- seq(0,0.9, by=0.1) > identical(0.3, corr[4]) [1] FALSE > all.equal(0.3, corr[4]) [1] TRUE apply() is likely to be more elegant in this case than a for loop. Sarah On Fri, May 28, 2010 at 9:52 AM, li li <hannah....@gmail.com> wrote: > Hi all, > I have a function rho.f which gives a list of estimators. I have the > following problems. > rho.f(0.3) gives me the right answer. However, if I use rho.f(corr[4]) give > me a different > answer, even though corr[4]==0.3. > This prevents me from using a for loop. Can someone give me some help? > Thank you very much in advance. > Hannah > >> rho.f(0.3) > $est.1 > [1] 0 0 0 0 0 0 > $est.2 > [1] 0 0 0 0 0 0 > $est.3 > [1] 0 0 0 0 0 0 > $est.4 > [1] 0 0 0 0 0 0 > $est.5 > [1] 0 0 0 0 0 0 > >> corr <- seq(0,0.9, by=0.1) >> corr[4] > [1] 0.3 > >> rho.f(corr[4]) > $est.1 > [1] 0.0 0.0 2.5 0.0 5.0 0.0 > $est.2 > [1] 0.00000 0.00000 0.00000 0.00000 3.72678 0.00000 > $est.3 > [1] 0.000000 0.000000 0.000000 0.000000 2.777778 0.000000 > $est.4 > [1] 0.00000 0.00000 0.00000 0.00000 13.88889 0.00000 > $est.5 > [1] 0.00000 0.00000 0.00000 0.00000 13.88889 0.00000 >> > -- Sarah Goslee http://www.functionaldiversity.org ______________________________________________ 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.