[R] Power functions?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Jan 3 22:51:32 CET 2009
Please post to only one of
r-help at r-project.org
r-help at stat.math.ethz.ch
not to both, as the same list then got two copies.
On Sat, 3 Jan 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.
See ?Syntax, linked from ?`^` :
The following unary and binary operators are defined. They are
listed in precedence groups, from highest to lowest.
'[ [[' indexing
':: :::' access variables in a name space
'$ @' component / slot extraction
'^' exponentiation (right to left)
'- +' unary minus and plus
so -1^2 is -(1^2) not (-1)^2.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list