%<>%
operator in R mean? <-
? %<>%
operator in R mean? <-
? This operator is from the magrittr
package and it is for you to pass an object to a function at the same time by modifying the object you passed.
For example, suppose the following x
in text format:
library(magrittr)
x <- "1"
Suppose you want to convert this x
to numeric. One way to do this is to assign x
to the result of the as.numeric
function on itself:
x <- as.numeric(x)
With %<>%
you do the same thing without having to type x
twice, because the %<>%
operator passes x
to as.numeric
and then rewrites x
:
x %<>% as.numeric # mesma coisa de x <- x %>% as.numeric
That is, while <-
modifies only the left-hand variable with the right expression, %<>%
modifies the left-hand variable after passing this variable to a function that is on the right.
In the background this is a syntax question, such as %>%
.