Published on

Solution for “Error: could not find function "%>%"” when running R programs

Problem: Running into the following error when trying to run the R language code snippet below:

# Code:
heights %>%
  mutate(height = round(height)) %>%
  group_by(height) %>%
  summarize(p = mean(sex == "Male")) %>%
  qplot(height, p, data=.)

# Error:
Error in heights %>% mutate(height = round(height)) %>% group_by(height) %>%  :
  could not find function "%>%"

Solution: There are a number of potential solutions for this issue but what worked for me was to install the margrittr package by running the following command in the R console:



Thanks for reading this blog post!

If you have any questions or concerns please feel free to post a comment in this post and I will get back to you if I find the time.

If you found this article helpful please share it and make sure to follow me on Twitter and GitHub, connect with me on LinkedIn and subscribe to my YouTube channel.