Life expectancy: Malaysia-clean file

Load library

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.2     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)
library(janitor)

Attaching package: 'janitor'

The following objects are masked from 'package:stats':

    chisq.test, fisher.test

Load data

state_group_all <- read_excel("input/Summary Tables, 2021-2023.xlsx", 
                           sheet = "Jadual 1.1",
                           range = "A5:J27",
                           col_names = T) %>% 
  clean_names()
New names:
• `` -> `...2`
• `` -> `...3`
state_group_male <- read_excel("input/Summary Tables, 2021-2023.xlsx", 
                           sheet = "Jadual 1.1",
                           range = "A33:J48",
                           col_names = F)
New names:
• `` -> `...1`
• `` -> `...2`
• `` -> `...3`
• `` -> `...4`
• `` -> `...5`
• `` -> `...6`
• `` -> `...7`
• `` -> `...8`
• `` -> `...9`
• `` -> `...10`
state_group_female <- read_excel("input/Summary Tables, 2021-2023.xlsx", 
                           sheet = "Jadual 1.1",
                           range = "A69:J84",
                           col_names = F)
New names:
• `` -> `...1`
• `` -> `...2`
• `` -> `...3`
• `` -> `...4`
• `` -> `...5`
• `` -> `...6`
• `` -> `...7`
• `` -> `...8`
• `` -> `...9`
• `` -> `...10`

Cleaning

State

  • Remove unnecessary columns & rows
## Remove unnecessary columns
state_group_all <- state_group_all %>% 
  select(negeri_state, x2023e)

state_group_all <- state_group_all %>% 
  slice(7:22)

State with gender

  • Rename columns

  • Remove unnecessary columns & rows

state_group_male <- state_group_male %>% 
  select(...1,...10)

state_group_female <- state_group_female %>% 
  select(...1,...10)

Export

write_csv(state_group_all,"source/state_group_all.csv")
write_csv(state_group_male,"source/state_group_male.csv")
write_csv(state_group_female,"source/state_group_female.csv")