# [R] problem with a function

Sarah Goslee sarah.goslee at gmail.com
Fri May 28 16:06:12 CEST 2010

```Hi Hannah,

No, we can't help because we have no idea what rho.f does - you didn't
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.hlx at 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
>   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

```