Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 493

R: Row means by group and year

$
0
0

I am trying to get an annual average of a column by group. I am a bit stumped with how to proceed.

Say my data looks like this:

YearGroupFullMonth
2022Group 11January
2022Group 25January
2022Group 36January
2023Group 14December
2023Group 23December
2023Group 34December

So the Month column is January to December, just shortened for simplicity. I would like to create another column, called "Annual average" which is the average of column "Full" for each year. The tricky part is I need it by Group as well. The end result is that the "Annual Average" column will have an average by year and by group such that for every year and group, the cell entry will be the same number (e.g., if the average for 2022 for Group 1 is 10, then the cell entries will be 10 for each row for Group 1 in 2022).

Any help is much appreciated!

So far, my attempts have only generated a single row mean, not differentiated by year or group.


Viewing all articles
Browse latest Browse all 493

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>