[R] R: to the power

Duncan Murdoch murdoch at stats.uwo.ca
Tue Jul 12 15:51:36 CEST 2005


On 7/12/2005 9:29 AM, Robin Hankin wrote:
> Hi
> 
> I find that one often needs to keep reals real and complexes complex.
> 
> Try this:
> 
> "cuberooti" <-
>    function (x)
> {
>    if (is.complex(x)) {
>      return(sqrt(x + (0+0i)))
>    }
>    sign(x)*  abs(x)^(1/3)
> }
> 
> 
> best wishes
> 
> [see that (0+0i) sitting there!]

I don't understand this.

1.  I don't think you meant to use sqrt() there, did you??

2.  What effect does the 0+0i have?  x has already been determined to be 
complex.

Duncan Murdoch




More information about the R-help mailing list