[R] weird behavior with the 3rd root....

Duncan Murdoch murdoch at stats.uwo.ca
Sun Oct 26 21:23:38 CET 2008

On 26/10/2008 4:05 PM, Juan Manuel Barreneche wrote:
> Well, this is what i got...
>> -0.0841219200008394^(1/3)
> [1] -0.438163696867656
>> (-0.0841219200008394)^(1/3)
> [1] NaN
> and i don't have a clue of why this happens or how to avoid it, any suggestions?

R won't raise negative numbers to fractional powers, because it uses 
exp(log(x)*y) for x^y.  (If y is a whole number it will work.)

Your first case is -(x^y), your second is (-x)^y, so that's why you got 
the different answers.

To avoid it, don't try to take fractional powers of negative numbers.

Duncan Murdoch

More information about the R-help mailing list