Cleaning

Load the Package

library(tidyverse)
Warning: package 'ggplot2' was built under R version 4.5.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   4.0.1     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── 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

Import Original Dataset

df <- read_csv("data/femicide_data.csv")
Rows: 121796 Columns: 13
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (11): Iso3_code, Country, Region, Subregion, Indicator, Dimension, Categ...
dbl  (2): Year, VALUE

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Check the Dataset

glimpse(df)
Rows: 121,796
Columns: 13
$ Iso3_code             <chr> "ARM", "CHE", "COL", "CZE", "DEU", "FIN", "GTM",…
$ Country               <chr> "Armenia", "Switzerland", "Colombia", "Czechia",…
$ Region                <chr> "Asia", "Europe", "Americas", "Europe", "Europe"…
$ Subregion             <chr> "Western Asia", "Western Europe", "Latin America…
$ Indicator             <chr> "Persons arrested/suspected for intentional homi…
$ Dimension             <chr> "by citizenship", "by citizenship", "by citizens…
$ Category              <chr> "National citizens", "National citizens", "Natio…
$ Sex                   <chr> "Male", "Male", "Male", "Male", "Male", "Male", …
$ Age                   <chr> "Total", "Total", "Total", "Total", "Total", "To…
$ Year                  <dbl> 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013, …
$ `Unit of measurement` <chr> "Counts", "Counts", "Counts", "Counts", "Counts"…
$ VALUE                 <dbl> 35, 28, 15053, 69, 455, 70, 2764, 905, 229, 1, 8…
$ Source                <chr> "CTS", "CTS", "CTS", "CTS", "CTS", "CTS", "CTS",…

Rename and Select the Needed Columns

df1 <- df |>
  rename('iso3_code' = 'Iso3_code',
         'country' = 'Country',
         'region' = 'Region',
         'subregion' = 'Subregion',
         'indicator' = 'Indicator',
         'dimension' = 'Dimension',
         'category' = 'Category',
         'sex' = 'Sex',
         'age' = 'Age',
         'year' = 'Year',
         'measurement' = 'Unit of measurement',
         'value' = 'VALUE',
         'source' = 'Source') |>
    select(-source)

str(df1)
tibble [121,796 × 12] (S3: tbl_df/tbl/data.frame)
 $ iso3_code  : chr [1:121796] "ARM" "CHE" "COL" "CZE" ...
 $ country    : chr [1:121796] "Armenia" "Switzerland" "Colombia" "Czechia" ...
 $ region     : chr [1:121796] "Asia" "Europe" "Americas" "Europe" ...
 $ subregion  : chr [1:121796] "Western Asia" "Western Europe" "Latin America and the Caribbean" "Eastern Europe" ...
 $ indicator  : chr [1:121796] "Persons arrested/suspected for intentional homicide" "Persons arrested/suspected for intentional homicide" "Persons arrested/suspected for intentional homicide" "Persons arrested/suspected for intentional homicide" ...
 $ dimension  : chr [1:121796] "by citizenship" "by citizenship" "by citizenship" "by citizenship" ...
 $ category   : chr [1:121796] "National citizens" "National citizens" "National citizens" "National citizens" ...
 $ sex        : chr [1:121796] "Male" "Male" "Male" "Male" ...
 $ age        : chr [1:121796] "Total" "Total" "Total" "Total" ...
 $ year       : num [1:121796] 2013 2013 2013 2013 2013 ...
 $ measurement: chr [1:121796] "Counts" "Counts" "Counts" "Counts" ...
 $ value      : num [1:121796] 35 28 15053 69 455 ...

Save the Data

save(df1, file = "data/femicide.RData")