Re: [R] R: to the power

From: <allan_sta_staff_sci_main_uct_at_mail.uct.ac.za>
Date: Tue 12 Jul 2005 - 23:53:56 EST

hi all

i simply wanted to work with real numbers and thought that (-8)^(1/3) should work.

sorry for not making the question clearer.

/
allan

Quoting Duncan Murdoch <murdoch@stats.uwo.ca>:

> 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

>

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 Tue Jul 12 23:59:45 2005

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