[R] exponent confusion

Phineas Campbell pcampbell at econ.bbk.ac.uk
Wed Feb 22 18:41:56 CET 2006


> -0.7^1.22
[1] -0.6471718

(-0.7)^1.22
>NaN

Arithmetically this makes perfect sense, syntactically I'm not sure it does.

>z<-c(-0.7)
> z == -0.7
[1] TRUE
> z^1.22
[1] NaN


I remember a programming homily: if you are unsure of the operator
precedence then you shouldn't assume the person who has to maintain your
code has any better knowledge so you should make the order in which you want
expressions to be evaluated explicit.

Phineas



-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of tom wright
Sent: Wednesday, February 22, 2006 10:14 AM
To: R-Stat Help
Subject: [R] exponent confusion


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?

______________________________________________
R-help at 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




More information about the R-help mailing list