Hi! I'm a little new at R. Essentially, I have a dataframe consisting of countries (32 unique factors), years (from 1960-2019) and TFR. What I'd like to do is group my factor which has countries into the continent that they belong to and find the mean TFR value of those countries within a certain continent in a specific year. I've found out how to re-label the countries into continents with:
tfr_recoded <- tfr %>%
mutate(
Country = fct_collapse(
Country,
"Northern Europe" = c("Estonia","Denmark","Iceland","Finland","Norway","Sweden"),
"Eastern Europe" = c("Bulgaria", "Belarus", "Poland", "Lithuania", "Hungary", "Ukraine"),
"Western Europe" = c("Germany","United Kingdom", "France", "Switzerland", "Austria","Netherlands","Czechia", "Slovenia", "Slovakia", "Croatia"),
"Southern Europe" = c("Italy", "Spain", "Portugal"),
"Asia" = c("Taiwan", "Republic of Korea", "Japan"),
"America" = c("USA", "Chile", "Canada")))
But now I'm struggling to find out how to get the mean TFR of these continents (using the individual TFR rates of the countries) in each year! Added is a screenshot of the dataframe to hopefully help you understand. Many thanks