R/ons_uk_population_2023.R
ons_uk_population_2023.Rd
ONS Population Estimates for Mid-year 2023 National and subnational mid-year population estimates for the UK and its constituent countries by administrative area, age and sex (including components of population change, median age and population density).
data(ons_uk_population_2023)
Tibble with six columns
male or female
country/geography code
country of the UK
Country
year of age
the number of people in this group
ONS Estimates of the population for the UK, England, Wales, Scotland, and Northern Ireland
data(ons_uk_population_2023)
library(dplyr)
library(tidyr)
# create a dataset that has total population by age groups for England
ons_uk_population_2023 |>
filter(Name == "ENGLAND") |>
mutate(age_group = case_when(
as.numeric(age) <= 17 ~ "0-17",
as.numeric(age) >= 18 & as.numeric(age) <= 64 ~ "18-64",
as.numeric(age) >= 65 ~ "65+",
age == "90+" ~ "65+"
)) |>
group_by(age_group) |>
summarise(count = sum(count))
#> Warning: There were 4 warnings in `mutate()`.
#> The first warning was:
#> ℹ In argument: `age_group = case_when(...)`.
#> Caused by warning:
#> ! NAs introduced by coercion
#> ℹ Run `dplyr::last_dplyr_warnings()` to see the 3 remaining warnings.
#> # A tibble: 3 × 2
#> age_group count
#> <chr> <dbl>
#> 1 0-17 11998646
#> 2 18-64 34908590
#> 3 65+ 10783087