Finding mean and filtering by year

Hi All,

I am new to R and currently facing a roadblock. My data set has 4 columns (year , residential , commercial , industrial ).

The years are from 2016 - 2021, and I would like to know the code to find the mean of each year, separating it by residential, commercial and industrial.

Dataset
year residential commercial industrial

2016 9.43 8.48 6.93
2016 9.83 8.56 7.2
2016 10.3 8.63 8.49
2016 10.6 8.66 7.4
2016 11.0 8.79 7.36
2016 11.9 9.56 7.87
2016 12.1 9.56 8.51
2016 12.0 9.35 7.78
2016 12.3 9.44 7.48
2016 10.8 8.6 7.11

... with 55 more rows

It will be great if you have a sample data.

If I understand correctly , you wanna mean for residential, commercial and industrial in each year,

You can do test %>% group_by(year) %>% summarise_all(mean)

1 Like

Thank you so much I managed to solve this!

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.