I am experience a problem calculating the result when putting a vector to the power of a decimal. The problem is more specifically that negative numbers in the vector come back as NAN. This also happens if I assign the negative number to a variable. Some examples to explain:
> -5.718301^2.85
[1] -143.9498
> test<--5.718301
> test
[1] -5.718301
> test^2.85
[1] NaN
> c(5.718301)^2.85
[1] 143.9498
> c(-5.718301)^2.85
[1] NaN
Can anyone explain to me why this happens? And any way around it? The vector in question may have positive and negative values, therefore, I can’t assign a negative sign after.
Thanks in advance,
Aran
There is no real valued solution to
(-5.718301)^2.85and soNaNis the correct answer.What you are attempting here is akin to asking for the square root of a negative number.
When you successfully evaluated
the precedence of the operators meant that this was equivalent to
and of course that is well-defined.