You can use dplyr
functions, group_by()
and summarise()
.
You can learn more about data wrangling in general in this free ebook
https://r4ds.had.co.nz/transform.html
Or, if you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.
Also, please be aware that this is not supposed to be a support ticket where we follow along with all the stages of your project, this is mostly a Q & A forum so you should only ask one reasonably well defined question per topic, but you can open as many topics as you need.