Re: [R] WIERD: Basic computing in R

From: Marc Schwartz <>
Date: Tue, 01 Jul 2008 13:43:28 -0500

on 07/01/2008 01:15 PM wrote:
> Can someone please enlighten me as to why the following happens?

>> -2.7^8.6

> [1] -5125.407
>> p<- -2.7 q<- 8.6 p^q
> [1] NaN

> R seems perfectly able to calculate -2.7^8.6, but fails when
> the exact same values are assigned to variables and then the
> computation is repeated. Thanks in advance for any suggetsions. Kris.

You are not seeing what you think you are seeing in the first result.

 > -2.7^8.6
[1] -5125.407

is parsed in the same way as:

 > -(2.7^8.6)
[1] -5125.407

In other words, it is parsed as:

 > 2.7^8.6
[1] 5125.407

and then negated.

If you were to 'properly' define the precedence of operation, you would use:

 > (-2.7)^8.6
[1] NaN

which is the same result you get when you use the vectors.

See R FAQ 7.33 Why are powers of negative numbers wrong?:

HTH, Marc Schwartz mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue 01 Jul 2008 - 18:45:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Jul 2008 - 19:31:35 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive