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
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.