7
- What the operator means
%<>%in r ? - What is your difference from
<-? - Under what circumstances can it be useful?
7
%<>% in r ? <- ? 7
That operator belongs to the package magrittr and it serves for you to pass an object to a function while 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 for numeric. One way to do this is to assign the x the result of the function as.numeric in itself:
x <- as.numeric(x)
With the %<>% you do the same thing without having to write the x twice as the operator %<>% passes the x to the as.numeric and then rewrite x:
x %<>% as.numeric # mesma coisa de x <- x %>% as.numeric
That is, while the <- only modifies the left-hand variable with the right-hand expression, the %<>% modifies the left variable after passing this variable to a function on the right.
At the bottom this is a matter of syntax, such as the %>%.
Browser other questions tagged r operators
You are not signed in. Login or sign up in order to post.