%^=% {infixit} | R Documentation |
Exponentiation variable reassignment
Description
Updates the left-hand, numeric type object by raising it to the power of the right-hand value, reassigning the result to the left-hand object.
Usage
lhs %^=% rhs
Arguments
lhs |
An numeric object existing in the global/ parent environment. |
rhs |
A numeric value to raise the lhs by |
Details
Currently in R, if you want to update the value
of a numeric object to be the outcome of some
arithmetic operation, you have to initialize the
object and then reassign it. For example:
apple <- 2
and then apple <- apple ^ 3
. This
sort of thing is generally referred to as
augmented variable assignment. This function allows
users to update the value of an object through
raising it to the power of the value on the right-hand side.
Value
Returns the arithmetically-updated left-hand object into the environment the operation was performed in.
Examples
{
example <- 2
example %^=% 3
example # returns 8
}