no applicable method for 'group_by' applied to an object of class "function"


I have a cvs file and want to run a randomised trial on it and generate a plot, but when running i've been getting an error in the group_by, see below. How do I fix this?

diff_in_means<-chick_data_2022_03_22 %>%

  • group_by(growth_rate)%>%
  • summarise(mean=mean(growth_rate))%>%
  • summarise(diff=diff(mean))%>%as.numeric()

Error in UseMethod("group_by") :
no applicable method for 'group_by' applied to an object of class "function"

Looks like there’s an error in the second line -
readr::read_csv is not doing anything. I think it should be -
readr::read_csv(“name of csv file”)
You may have to include the path as well.

Hi @Tsuki and welcome to the community!

It's a little difficult to troubleshoot without a reproducible example of what your data look like. Take a look at FAQ: What's a reproducible example (`reprex`) and how do I create one? when you get a chance.

In addition to what @Pathmes has added, the summarise function may be getting confused where your newly created column names are the same as built-in function names.

Once you get the data read in correctly, I would try something like:

diff_in_means <- chick_data_2022_03_22 %>%
  group_by(growth_rate) %>%
  summarise(mean_growth = mean(growth_rate),
    diff_growth_rate = diff(mean_growth))


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.