inplace | R Documentation |
The x %:=% f
operator performs
in-place modification of some object x
with a function f
.
For example this:
mtcars$mpg[mtcars$cyl > 6] <- mtcars$mpg[mtcars$cyl>6]^2
Can now be re-written as:
mtcars$mpg[mtcars$cyl > 6] %:=% \(x) x^2
x %:=% f
x |
a variable. |
f |
a (possibly anonymous) function to be applied in-place on |
This operator does not return any value:
It is an in-place modifier, and thus modifies the object directly.
tinycodet_dry
set.seed(1)
object <- matrix(rpois(10, 10), ncol = 2)
print(object)
y <- 3
object %:=% \(x) x + y # same as object <- object + y
print(object)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.