Taking means using two criteria for the group_by argument

I have a large data set with 3 columns: "survey", "time_interval", and "mass".
survey has an integer value from 1-3, and time_interval has an integer value from 1-8. Mass has decimal values. dataframe=JS_CU

How can I take mean of each time interval for each survey?

I tried to start by using group_by, but it I can't figure out how to input two criteria for the grouping. I get an error when I write this:

group_by(JS_CU$time_int, JS_CU$survey)

What's the best way to go about trying to get these means?

You are mixing base R with tidyverse syntax here, when working with tidyverse functions there is no need for JS_CU$ before the variable name. I can't test this because you are not providing a REPRoducible EXample (reprex) but I think your code should be like this:

JS_CU %>% 
  group_by(time_int, survey) %>% 
  summarise(mass_mean = mean(mass, na.rm = TRUE))
1 Like

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