Re: [R] exponent confusion

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Thu 23 Feb 2006 - 04:00:25 EST

On Wed, 22 Feb 2006, tom wright wrote:

> please excuse me if this ones a basic error
>
>> y<-c(-0.7,-0.6,-0.5)
>> -0.7^1.22
> [1] -0.6471718
>
>> y^1.22
> [1] NaN NaN NaN
>
> am I missing something important in my basic math?
>

Yes.

Non-integer powers of negative numbers don't work (well, they are complex numbers)

The first example appears to work but only because -0.7^1.22 is -(0.7^1.22) not (-0.7)^1.22. See help(Syntax) for operator precedence in R. This does keep confusing people, and perhaps should be a FAQ, but it is fairly standard in programming languages.

         -thomas



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 Thu Feb 23 04:43:10 2006

This archive was generated by hypermail 2.1.8 : Thu 23 Feb 2006 - 06:23:11 EST