Home > Software engineering >  Creating new dataset with averages in R
Creating new dataset with averages in R

Time:03-04

I currently have a dataset that looks like this:

enter image description here

I would like to create a new dataset of the average rate for each Jurisdiction. It would look something like this:

enter image description here

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)
  )
  • Related