[R] exponent confusion

Thomas Lumley tlumley at u.washington.edu
Wed Feb 22 18:00:25 CET 2006


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




More information about the R-help mailing list