Re: [R] R: to the power

From: Robin Hankin <r.hankin_at_noc.soton.ac.uk>
Date: Wed 13 Jul 2005 - 00:01:00 EST

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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Jul 13 00:07:03 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:33 EST