[R] Power functions?
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Sat Jan 3 23:11:48 CET 2009
rkevinburton at charter.net wrote:
> I had a question about the basic power functions in R.
>
> For example from the R console I enter:
>
> -1 ^ 2
> [1] -1
>
> but also
>
> -1^3
> [1] -1
>
> -0.1^2
> [1] -0.01
>
> Normally pow(-1, 2) return either -Infinity or NaN. Has R taken over the math functions? If so I would think that -1^2 is 1 not -1 and -0.1^2 is 0.01 not -0.01.
>
(-1)^2
# 1, not -1
it's similar to the case
1:3-1
1:(3-1)
it's about operator precedence.
vQ
More information about the R-help
mailing list