I currently have a dataset that looks like this:
I would like to create a new dataset of the average rate for each Jurisdiction. It would look something like this:
Do I need to use a subset option or do I need convert this table from long to wide? I'm a bit lost on the code I need to write to make this work.
Any help would be appreciated!
Thanks!
CodePudding user response:
Likely something like this:
dplyr
library(dplyr)
dat %>%
group_by(Jurisdiction) %>%
summarize(
Years = paste(range(2021:2025), collapse = "-"),
across(starts_with("rate"), mean)
)