[R] about vector to the power of a decimal

Phil Spector spector at stat.berkeley.edu
Fri May 13 02:10:24 CEST 2011


Please take a look at FAQ 7.33 
(http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-are-powers-of-negative-numbers-wrong_003f)

Basically, what you're really calculating is

> -(2^2.1)
[1] -4.287094

You can't raise a negative number to a fractional power, unless
you specify it as a complex number

> (-2)^2.1
[1] NaN
> complex(real=-2)^2.1
[1] 4.077269+1.324785i


 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Fri, 13 May 2011, 张静思 wrote:

> Hi
> why I can't do this?
> m<-c(1,-2,3)
> m^2.1
> with a negative number in it ,but I can do this to a single negative number like -2^2.1~
> Thank you ~
>
>
> JIngsi
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


More information about the R-help mailing list