Skip to content

Commit

Permalink
Added source of dataset and executed styler
Browse files Browse the repository at this point in the history
  • Loading branch information
jacgrout committed Oct 17, 2024
1 parent 74722ee commit 1479282
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
18 changes: 9 additions & 9 deletions R/ons_uk_population_2023.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
#'
#' # 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))
#'
#'
#' 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))
#'
"ons_uk_population_2023"
34 changes: 34 additions & 0 deletions data-raw/ons_uk_population_2023.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Source: https://www.ons.gov.uk/peoplepopulationandcommunity/populationandmigration/populationestimates/datasets/populationestimatesforukenglandandwalesscotlandandnorthernireland

library(readxl)
library(tidyverse)
library(tidyr)

# Load the data in
population_data_2023_f <- read_excel(
"mye23tablesuk.xlsx", # add full file path here before file name
sheet = "MYE2 - Females",
skip = 7
)

population_data_2023_m <- read_excel(
"mye23tablesuk.xlsx", # add full file path here before file name
sheet = "MYE2 - Males",
skip = 7
)


# pivot longer
population_data_2023_f <- population_data_2023_f |>
select(!`All ages`) |>
pivot_longer(`0`:`90+`, names_to = "age", values_to = "count")

population_data_2023_m <- population_data_2023_m |>
select(!`All ages`) |>
pivot_longer(`0`:`90+`, names_to = "age", values_to = "count")

population_data_combined <- bind_rows(
females = population_data_2023_f,
males = population_data_2023_m,
.id = "sex"
)

0 comments on commit 1479282

Please sign in to comment.