[R] R: to the power

Robin Hankin r.hankin at noc.soton.ac.uk
Tue Jul 12 16:01:00 CEST 2005


On 12 Jul 2005, at 14:51, Duncan Murdoch wrote:

> On 7/12/2005 9:29 AM, Robin Hankin wrote:
>

[bogus function snipped]

> 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
>

Er, guilty on all counts.  I plead the hot weather.

I intended to modify and post the following function
for cube roots.


"sqrti" <-
   function (x)
{
   if (is.complex(x)) {
     return(sqrt(x))
   }
   if (any(x < 0)) {
     return(sqrt(x + 0i))
   }
   return(sqrt(x))
}

[which deals with square roots in a consistent way, handling positive  
reals,
and negative reals, and complexes, in a nice way]

sorry about that




rksh


--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743




More information about the R-help mailing list