Search code examples
rtidyverse

Is there a %$% operator?


In the book R for Data Science, there is an operator %$%, as in the example code below. But when I run that code, I get the error message "there is no such operator". Can anyone help with this?

library(tidyverse)
mtcars %$%
  cor(disp, mpg)

Solution

  • According to r-blogger, %$% is not exported from {tidyverse}, instead it is part of the magrittr package, so you will need to load {magrittr}.

    install.packages("magrittr") # You only need to install it once. 
    library(magrittr) 
    mtcars %$%
      cor(disp, mpg)