[R] Coercing of types when raising a number to a series of powers
David Winsemius
dwinsemius at comcast.net
Fri Feb 8 03:41:38 CET 2013
On Feb 7, 2013, at 6:21 PM, Julio Sergio wrote:
> Julio Sergio <juliosergio <at> gmail.com> writes:
>
>>
>> I'm trying to produce a series of powers of a number as follows:
>>
>> |> 0.05^0:5
>
>
> I'm sorry for the question. The answer is simple: the result is due to
> operator precedence not to coercing:
>
> |> 0.05^(0:5)
> [1] 1.000e+00 5.000e-02 2.500e-03 1.250e-04 6.250e-06 3.125e-07
You might want to review the rest of the R0FAQ: The item regarding operator precedence is actually about the higher precedence of "^" relative to the minus sign, but there are a lot of goodies in section 7:
FAQ 7:31 shows how you can see what the parsed expression looks like:
> as.list(quote(-2^2))
[[1]]
`-`
[[2]]
2^2
In your case it's:
> as.list(quote( 0.05^0:5 ) )
[[1]]
`:`
[[2]]
0.05^0
[[3]]
[1] 5
--
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list