Data Cleaning

Tasks

  1. Identifies data cleaning issues (variable name, type, etc.)
  2. Applies appropriate cleaning strategies
  3. Explains each step clearly (use # inside code chunk or write in texts)
  4. Saves cleaned dataset as .RData

0. Preliminary Set-Up

Load the package

library(tidyverse)
── 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   3.5.2     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.1.0     
── 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 datases

gdp <- read_csv("data/gdp.csv")
New names:
• `` -> `...3`
Warning: One or more parsing issues, call `problems()` on your data frame for details,
e.g.:
  dat <- vroom(...)
  problems(dat)
Rows: 268 Columns: 3
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (3): Data Source, World Development Indicators, ...3

ℹ 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.
PlasticWasteRegion <- read_csv("data/plasticwasteregion.csv")
Rows: 200 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): Entity, Code
dbl (5): Year, Recycled, Incinerated, Littered and mismanaged, Landfilled

ℹ 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.
PlasticWasteCountry <- read_csv("data/plasticwastecountry.csv")
Rows: 186 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): Entity, Code
dbl (2): Year, Per capita plastic waste (kg/person/day)

ℹ 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.

1. GDP Dataset Cleaning

Chack the dataset

Take a glimpse at the dataset

library(tidyverse)

gdp_raw <- read_csv("data/gdp.csv", skip = 3) |>
  glimpse()
New names:
Rows: 266 Columns: 70
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(4): Country Name, Country Code, Indicator Name, Indicator Code dbl (65): 1960,
1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, ... lgl (1): ...70
ℹ 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.
• `` -> `...70`
Rows: 266
Columns: 70
$ `Country Name`   <chr> "Aruba", "Africa Eastern and Southern", "Afghanistan"…
$ `Country Code`   <chr> "ABW", "AFE", "AFG", "AFW", "AGO", "ALB", "AND", "ARB…
$ `Indicator Name` <chr> "GDP per capita (current US$)", "GDP per capita (curr…
$ `Indicator Code` <chr> "NY.GDP.PCAP.CD", "NY.GDP.PCAP.CD", "NY.GDP.PCAP.CD",…
$ `1960`           <dbl> NA, 186.12183, NA, 121.93993, NA, NA, NA, NA, NA, 778…
$ `1961`           <dbl> NA, 186.94178, NA, 127.45419, NA, NA, NA, 212.88966, …
$ `1962`           <dbl> NA, 197.40240, NA, 133.82704, NA, NA, NA, 210.80541, …
$ `1963`           <dbl> NA, 225.44049, NA, 139.00829, NA, NA, NA, 225.80063, …
$ `1964`           <dbl> NA, 208.99975, NA, 148.54938, NA, NA, NA, 243.89743, …
$ `1965`           <dbl> NA, 226.87651, NA, 155.56522, NA, NA, NA, 256.18014, …
$ `1966`           <dbl> NA, 240.95523, NA, 162.11077, NA, NA, NA, 263.95084, …
$ `1967`           <dbl> NA, 243.81732, NA, 144.94348, NA, NA, NA, 276.93297, …
$ `1968`           <dbl> NA, 257.19008, NA, 146.18917, NA, NA, NA, 307.53680, …
$ `1969`           <dbl> NA, 281.62928, NA, 161.92141, NA, NA, NA, 329.43142, …
$ `1970`           <dbl> NA, 276.78206, NA, 218.67629, NA, NA, 3935.41128, 357…
$ `1971`           <dbl> NA, 294.86615, NA, 195.86200, NA, NA, 4169.69537, 402…
$ `1972`           <dbl> NA, 311.51902, NA, 230.07079, NA, NA, 4940.29696, 470…
$ `1973`           <dbl> NA, 389.79697, NA, 280.64930, NA, NA, 6151.02717, 602…
$ `1974`           <dbl> NA, 463.5498, NA, 368.3019, NA, NA, 7139.5745, 1124.9…
$ `1975`           <dbl> NA, 479.1622, NA, 413.3714, NA, NA, 7925.4158, 1205.4…
$ `1976`           <dbl> NA, 468.8563, NA, 480.4527, NA, NA, 7721.2886, 1458.1…
$ `1977`           <dbl> NA, 518.4506, NA, 490.8478, NA, NA, 8167.9229, 1630.3…
$ `1978`           <dbl> NA, 571.7203, NA, 523.7881, NA, NA, 9409.5085, 1728.2…
$ `1979`           <dbl> NA, 634.5619, NA, 624.8783, NA, NA, 11996.4073, 2251.…
$ `1980`           <dbl> NA, 773.4395, NA, 757.0756, 729.1120, 590.6077, 12474…
$ `1981`           <dbl> NA, 777.8331, NA, 1324.5466, 657.9826, 663.2942, 1046…
$ `1982`           <dbl> NA, 725.7281, NA, 1162.1307, 634.2215, 668.4545, 9697…
$ `1983`           <dbl> NA, 732.5887, NA, 872.8327, 636.8328, 661.5468, 8082.…
$ `1984`           <dbl> NA, 650.5635, NA, 737.6749, 650.4911, 639.4847, 7808.…
$ `1985`           <dbl> NA, 554.4391, NA, 753.7998, 772.4688, 639.8659, 7911.…
$ `1986`           <dbl> 6767.5592, 578.6040, NA, 581.3907, 697.5266, 693.8735…
$ `1987`           <dbl> 8244.0457, 665.1198, NA, 581.5238, 770.1011, 674.7934…
$ `1988`           <dbl> 10056.2614, 704.4662, NA, 560.3806, 807.4396, 652.774…
$ `1989`           <dbl> 11507.2172, 728.5493, NA, 509.3267, 907.7479, 697.995…
$ `1990`           <dbl> 12187.5364, 822.7939, NA, 590.3214, 965.8668, 617.230…
$ `1991`           <dbl> 13233.9905, 864.5639, NA, 603.8789, 881.9195, 336.587…
$ `1992`           <dbl> 13892.60514, 733.24386, NA, 563.31008, 668.70602, 200…
$ `1993`           <dbl> 14700.9598, 709.6593, NA, 570.8886, 449.7279, 367.279…
$ `1994`           <dbl> 16055.2878, 701.0416, NA, 577.5487, 334.9736, 586.416…
$ `1995`           <dbl> 16548.7174, 766.8206, NA, 863.9506, 404.2948, 911.320…
$ `1996`           <dbl> 16620.9546, 747.0697, NA, 1065.6835, 531.1154, 1020.9…
$ `1997`           <dbl> 17750.0096, 767.6842, NA, 1088.9968, 521.7029, 728.54…
$ `1998`           <dbl> 18828.0871, 697.3527, NA, 1137.7445, 429.1881, 831.17…
$ `1999`           <dbl> 19216.1972, 670.6978, NA, 521.3647, 392.7255, 1056.34…
$ `2000`           <dbl> 20681.0230, 707.1204, 174.9310, 516.9323, 563.7338, 1…
$ `2001`           <dbl> 20740.1326, 626.1691, 138.7068, 530.6532, 533.5862, 1…
$ `2002`           <dbl> 21307.2483, 625.9988, 178.9541, 616.7960, 882.1478, 1…
$ `2003`           <dbl> 21949.4860, 809.9681, 198.8711, 694.5009, 992.6990, 1…
$ `2004`           <dbl> 23700.6320, 981.7446, 221.7637, 840.2521, 1266.2109, …
$ `2005`           <dbl> 24171.8371, 1115.7140, 254.1842, 1001.6046, 1916.4684…
$ `2006`           <dbl> 24845.6585, 1220.0025, 274.2186, 1236.6281, 2617.0520…
$ `2007`           <dbl> 26736.3089, 1362.3107, 376.2232, 1407.6421, 3141.0460…
$ `2008`           <dbl> 28171.9094, 1421.1186, 381.7332, 1668.8411, 4103.0669…
$ `2009`           <dbl> 25134.7712, 1386.5902, 452.0537, 1454.7283, 3136.6455…
$ `2010`           <dbl> 24093.1402, 1601.7277, 560.6215, 1663.9669, 3597.3429…
$ `2011`           <dbl> 25712.3843, 1735.5849, 606.6947, 1844.1986, 4615.9106…
$ `2012`           <dbl> 25119.6655, 1702.9691, 651.4171, 1941.3696, 5086.0274…
$ `2013`           <dbl> 25813.5767, 1673.2211, 637.0871, 2131.6621, 5057.7479…
$ `2014`           <dbl> 26129.8391, 1656.1677, 625.0549, 2221.0107, 5005.9997…
$ `2015`           <dbl> 27458.2253, 1479.6153, 565.5697, 1860.7277, 3213.9026…
$ `2016`           <dbl> 27441.5297, 1329.8073, 522.0822, 1630.0394, 1807.9529…
$ `2017`           <dbl> 28440.0520, 1520.2122, 525.4698, 1574.2306, 2437.2597…
$ `2018`           <dbl> 30082.1276, 1538.9017, 491.3372, 1720.1403, 2538.5914…
$ `2019`           <dbl> 31096.2051, 1493.8179, 496.6025, 1798.3407, 2189.8557…
$ `2020`           <dbl> 22855.9323, 1344.1032, 510.7871, 1680.0393, 1449.9229…
$ `2021`           <dbl> 27200.0611, 1522.3933, 356.4962, 1765.9548, 1925.8747…
$ `2022`           <dbl> 30559.5335, 1628.3189, 357.2612, 1796.6686, 2929.6945…
$ `2023`           <dbl> 33984.7906, 1510.7430, 413.7579, 1599.3930, 2309.5341…
$ `2024`           <dbl> NA, 1567.6358, NA, 1284.1544, 2122.0837, 10011.6280, …
$ ...70            <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…

Check the head of the dataset

# Check the first ten (10) rows

head(gdp_raw, 10)
# A tibble: 10 × 70
   `Country Name` `Country Code` `Indicator Name` `Indicator Code` `1960` `1961`
   <chr>          <chr>          <chr>            <chr>             <dbl>  <dbl>
 1 Aruba          ABW            GDP per capita … NY.GDP.PCAP.CD      NA     NA 
 2 Africa Easter… AFE            GDP per capita … NY.GDP.PCAP.CD     186.   187.
 3 Afghanistan    AFG            GDP per capita … NY.GDP.PCAP.CD      NA     NA 
 4 Africa Wester… AFW            GDP per capita … NY.GDP.PCAP.CD     122.   127.
 5 Angola         AGO            GDP per capita … NY.GDP.PCAP.CD      NA     NA 
 6 Albania        ALB            GDP per capita … NY.GDP.PCAP.CD      NA     NA 
 7 Andorra        AND            GDP per capita … NY.GDP.PCAP.CD      NA     NA 
 8 Arab World     ARB            GDP per capita … NY.GDP.PCAP.CD      NA    213.
 9 United Arab E… ARE            GDP per capita … NY.GDP.PCAP.CD      NA     NA 
10 Argentina      ARG            GDP per capita … NY.GDP.PCAP.CD     778.   971.
# ℹ 64 more variables: `1962` <dbl>, `1963` <dbl>, `1964` <dbl>, `1965` <dbl>,
#   `1966` <dbl>, `1967` <dbl>, `1968` <dbl>, `1969` <dbl>, `1970` <dbl>,
#   `1971` <dbl>, `1972` <dbl>, `1973` <dbl>, `1974` <dbl>, `1975` <dbl>,
#   `1976` <dbl>, `1977` <dbl>, `1978` <dbl>, `1979` <dbl>, `1980` <dbl>,
#   `1981` <dbl>, `1982` <dbl>, `1983` <dbl>, `1984` <dbl>, `1985` <dbl>,
#   `1986` <dbl>, `1987` <dbl>, `1988` <dbl>, `1989` <dbl>, `1990` <dbl>,
#   `1991` <dbl>, `1992` <dbl>, `1993` <dbl>, `1994` <dbl>, `1995` <dbl>, …

Check the Data Summary through SkimR

Load the package

library(skimr)

Check the summary through skim

skim(gdp_raw)
Data summary
Name gdp_raw
Number of rows 266
Number of columns 70
_______________________
Column type frequency:
character 4
logical 1
numeric 65
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
Country Name 0 1 4 73 0 266 0
Country Code 0 1 3 3 0 266 0
Indicator Name 0 1 28 28 0 1 0
Indicator Code 0 1 14 14 0 1 0

Variable type: logical

skim_variable n_missing complete_rate mean count
…70 266 0 NaN :

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
1960 115 0.57 470.95 592.71 25.08 123.30 220.07 499.87 3002.09 ▇▁▁▁▁
1961 112 0.58 490.32 616.79 27.27 127.45 205.02 538.36 3062.97 ▇▁▁▁▁
1962 110 0.59 537.85 728.88 27.95 129.53 208.30 574.69 4748.39 ▇▁▁▁▁
1963 110 0.59 570.69 752.76 25.80 138.94 228.86 610.22 4444.52 ▇▁▁▁▁
1964 110 0.59 616.90 810.34 17.33 144.58 241.38 707.38 4378.78 ▇▁▁▁▁
1965 104 0.61 671.95 839.62 15.12 155.79 270.40 851.13 4023.99 ▇▁▁▁▁
1966 103 0.61 715.68 906.07 11.80 164.11 278.57 895.79 4176.11 ▇▁▁▁▁
1967 99 0.63 729.06 937.00 16.55 161.73 281.53 844.84 4331.58 ▇▁▁▁▁
1968 98 0.63 762.98 983.73 21.55 166.23 300.66 847.35 4691.63 ▇▁▁▁▁
1969 98 0.63 826.62 1060.21 21.51 175.15 315.05 901.09 5025.09 ▇▁▁▁▁
1970 76 0.71 995.67 1421.49 20.72 200.49 352.82 1294.89 12098.20 ▇▁▁▁▁
1971 75 0.72 1095.33 1575.27 21.13 208.78 383.55 1366.85 13334.40 ▇▁▁▁▁
1972 75 0.72 1270.76 1866.08 23.29 228.30 427.22 1558.48 16187.43 ▇▁▁▁▁
1973 75 0.72 1617.14 2417.51 24.80 279.47 538.01 2171.92 20882.02 ▇▁▁▁▁
1974 75 0.72 2158.56 3441.96 41.41 338.35 701.08 2560.81 23822.97 ▇▁▁▁▁
1975 71 0.73 2325.07 3817.66 35.16 364.25 717.76 2715.12 27920.74 ▇▁▁▁▁
1976 71 0.73 2532.71 4215.74 39.17 398.76 762.78 2933.02 31196.98 ▇▁▁▁▁
1977 68 0.74 2778.29 4632.31 27.86 441.79 862.68 3207.80 35020.36 ▇▁▁▁▁
1978 69 0.74 3146.15 5054.22 29.26 502.70 982.60 3359.57 37607.79 ▇▁▁▁▁
1979 68 0.74 3732.49 6130.06 29.21 557.44 1113.62 4122.07 44989.97 ▇▁▁▁▁
1980 58 0.78 4249.54 7556.03 31.25 606.06 1243.27 4609.16 58005.34 ▇▁▁▁▁
1981 58 0.78 4127.07 7007.96 32.81 652.42 1290.99 4947.16 48793.44 ▇▁▁▁▁
1982 57 0.79 3942.27 6430.04 42.95 626.53 1310.02 4598.76 45074.55 ▇▁▁▁▁
1983 57 0.79 3778.47 5910.02 39.29 621.07 1363.44 4475.30 39075.84 ▇▂▁▁▁
1984 55 0.79 3717.65 5672.36 36.33 580.84 1319.23 4507.28 36582.37 ▇▁▁▁▁
1985 53 0.80 3687.48 5563.47 40.38 571.42 1220.84 4656.25 37689.86 ▇▁▁▁▁
1986 53 0.80 4202.65 6463.21 42.42 541.14 1425.16 5181.88 52082.45 ▇▁▁▁▁
1987 46 0.83 4752.64 7669.43 41.15 586.35 1381.70 5259.09 62456.07 ▇▁▁▁▁
1988 43 0.84 5129.12 8286.04 39.92 570.51 1303.78 5679.99 67180.58 ▇▁▁▁▁
1989 43 0.84 5254.63 8369.31 51.34 586.04 1356.28 5928.95 66815.71 ▇▁▁▁▁
1990 26 0.90 5815.00 9647.18 53.12 650.58 1557.09 6529.21 81734.87 ▇▁▁▁▁
1991 25 0.91 5840.52 9780.28 22.95 624.39 1482.64 6824.34 80997.25 ▇▁▁▁▁
1992 24 0.91 6123.31 10447.37 30.25 575.65 1447.85 6730.67 88614.93 ▇▁▁▁▁
1993 23 0.91 5930.75 9984.03 53.74 560.45 1397.27 6704.86 82685.46 ▇▁▁▁▁
1994 22 0.92 6282.89 10691.02 61.49 580.80 1493.45 6997.47 86703.81 ▇▁▁▁▁
1995 19 0.93 7051.76 12249.83 62.14 682.85 1775.49 7109.34 99032.24 ▇▁▁▁▁
1996 19 0.93 7267.42 12427.56 71.41 721.20 1918.38 7333.77 98561.01 ▇▁▁▁▁
1997 17 0.94 7242.03 11836.57 108.04 728.55 1898.43 7944.60 88581.70 ▇▁▁▁▁
1998 16 0.94 7393.44 12237.62 126.47 687.78 1864.12 8169.11 90947.21 ▇▁▁▁▁
1999 16 0.94 7557.66 12606.65 96.32 615.94 1812.58 7862.97 89698.20 ▇▁▁▁▁
2000 14 0.95 7559.37 12207.03 122.27 635.43 1817.64 8377.66 81789.02 ▇▁▁▁▁
2001 13 0.95 7567.73 12152.37 118.46 637.21 1881.02 9611.96 82402.78 ▇▂▁▁▁
2002 9 0.97 8170.96 13024.38 109.59 683.86 2092.42 10586.05 90051.45 ▇▂▁▁▁
2003 9 0.97 9391.37 15169.22 111.41 764.63 2347.54 11487.22 111110.45 ▇▁▁▁▁
2004 9 0.97 10677.80 17123.99 125.19 922.87 2816.99 12886.37 125160.23 ▇▁▁▁▁
2005 9 0.97 11572.81 18207.60 147.23 1067.92 3146.83 14368.57 130538.74 ▇▁▁▁▁
2006 8 0.97 12932.72 20384.55 161.89 1226.98 3639.79 16279.37 143083.46 ▇▁▁▁▁
2007 8 0.97 14710.00 23495.95 166.16 1379.85 4396.31 18154.81 184558.56 ▇▁▁▁▁
2008 7 0.97 15776.32 25118.32 189.50 1555.78 5023.59 19105.00 204263.80 ▇▁▁▁▁
2009 5 0.98 14301.69 22042.88 199.10 1461.39 4799.79 17718.39 169150.27 ▇▁▁▁▁
2010 5 0.98 15028.00 22601.27 216.73 1663.97 5418.22 19847.23 161853.92 ▇▁▁▁▁
2011 4 0.98 16532.06 24850.08 230.07 1925.84 6010.39 20554.52 179363.98 ▇▁▁▁▁
2012 6 0.98 16415.17 24172.41 231.69 1930.44 6474.22 20093.56 165444.65 ▇▁▁▁▁
2013 6 0.98 16990.71 25609.19 234.84 2079.83 6706.86 20521.62 184940.66 ▇▁▁▁▁
2014 5 0.98 17316.21 26134.28 250.54 2164.94 6886.68 20638.77 195693.57 ▇▁▁▁▁
2015 7 0.97 15670.55 23570.96 280.97 1996.66 6141.20 19060.63 170437.10 ▇▁▁▁▁
2016 8 0.97 15792.96 23693.90 235.29 1951.96 5968.76 19035.38 173604.75 ▇▁▁▁▁
2017 8 0.97 16602.18 24446.06 236.69 2153.33 6323.21 20845.37 170663.38 ▇▁▁▁▁
2018 8 0.97 17601.84 25951.63 224.90 2146.98 6765.48 22657.44 188298.32 ▇▁▁▁▁
2019 8 0.97 17561.37 25667.09 210.24 2198.31 6761.50 22903.17 193746.79 ▇▁▁▁▁
2020 9 0.97 16317.31 24347.92 210.01 2081.74 6236.68 19966.48 176891.89 ▇▁▁▁▁
2021 9 0.97 18841.66 28826.96 214.09 2445.19 7051.20 22132.45 223823.36 ▇▁▁▁▁
2022 10 0.96 19495.39 28998.00 250.63 2388.57 7630.92 23994.45 226052.00 ▇▁▁▁▁
2023 18 0.93 19933.16 30893.89 192.07 2531.81 7856.95 23114.75 256580.52 ▇▁▁▁▁
2024 35 0.87 18153.23 24360.67 153.93 2592.86 7695.24 23918.98 138934.96 ▇▂▁▁▁

Issues to Fix

  • Convert the dataset from wide to long format
  • Remove unnecessary or empty columns
  • Filter out East/Southeast countries
  • Filter out only the years I need
  • Standardize country names for merging
  • Exclude missing values

Cleaning Process

Reshape from wide to long format

gdp_long <- gdp_raw |>
  rename(
    country_name = `Country Name`,
    country_code = `Country Code`
  ) |>
  pivot_longer(
    cols = `1960`:`2024`,
    names_to = "year",
    values_to = "gdp_per_capita"
  ) |>
  mutate(
    year = as.numeric(year)
  )

Keep only years 2010-2019

gdp_long <- gdp_long |>
  filter(year >= 2010, year <= 2019)

Standardize country names for merging

gdp_clean <- gdp_long |>
  mutate(
    country = case_when(
      country_name == "Korea, Rep." ~ "South Korea",
      country_name == "Hong Kong SAR, China" ~ "Hong Kong",
      country_name == "Viet Nam" ~ "Vietnam",
      country_name == "Brunei Darussalam" ~ "Brunei",
      TRUE ~ country_name
    )
  ) |>
  select(country, country_name, country_code, year, gdp_per_capita)

Define East Asia and Southeast Asia country groups

east_asia <- c("China", "Japan", "South Korea", "North Korea", "Hong Kong", "Taiwan")
southeast_asia <- c("Indonesia", "Philippines", "Vietnam", "Thailand", "Malaysia", "Singapore", "Cambodia", "Myanmar", "Brunei", "Timor-Leste")

asia_countries <- c(east_asia, southeast_asia)

Filter to East & Southeast Asia and add region_group

gdp_asia <- gdp_clean |>
  filter(country %in% asia_countries) |>
  mutate(
    region_group = case_when(
      country %in% east_asia ~ "East Asia",
      country %in% southeast_asia ~ "Southeast Asia",
      TRUE ~ "Other"
    )
  )
glimpse(gdp_asia)
Rows: 140
Columns: 6
$ country        <chr> "Brunei", "Brunei", "Brunei", "Brunei", "Brunei", "Brun…
$ country_name   <chr> "Brunei Darussalam", "Brunei Darussalam", "Brunei Darus…
$ country_code   <chr> "BRN", "BRN", "BRN", "BRN", "BRN", "BRN", "BRN", "BRN",…
$ year           <dbl> 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2…
$ gdp_per_capita <dbl> 34937.556, 46382.827, 46968.597, 44003.064, 41026.508, …
$ region_group   <chr> "Southeast Asia", "Southeast Asia", "Southeast Asia", "…

Save cleaned GDP data for later use

save(gdp_asia, file = "out/gdp_clean.RData")

2. Plastic Waste per Region Dataset Cleaning

Chack the dataset

Take a glimpse at the dataset

glimpse(PlasticWasteRegion)
Rows: 200
Columns: 7
$ Entity                    <chr> "Americas (excl. USA)", "Americas (excl. USA…
$ Code                      <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
$ Year                      <dbl> 2000, 2001, 2002, 2003, 2004, 2005, 2006, 20…
$ Recycled                  <dbl> 772024, 855770, 960160, 1066836, 1189151, 13…
$ Incinerated               <dbl> 199475, 208013, 219964, 230851, 243482, 2533…
$ `Littered and mismanaged` <dbl> 5346765, 5619297, 5989772, 6333178, 6729046,…
$ Landfilled                <dbl> 10031376, 10526961, 11197690, 11828031, 1255…

Check the head of the dataset

# Check the first ten (10) rows

head(PlasticWasteRegion, 10)
# A tibble: 10 × 7
   Entity     Code   Year Recycled Incinerated Littered and mismana…¹ Landfilled
   <chr>      <chr> <dbl>    <dbl>       <dbl>                  <dbl>      <dbl>
 1 Americas … <NA>   2000   772024      199475                5346765   10031376
 2 Americas … <NA>   2001   855770      208013                5619297   10526961
 3 Americas … <NA>   2002   960160      219964                5989772   11197690
 4 Americas … <NA>   2003  1066836      230851                6333178   11828031
 5 Americas … <NA>   2004  1189151      243482                6729046   12555211
 6 Americas … <NA>   2005  1304177      253364                7047497   13155670
 7 Americas … <NA>   2006  1443474      266485                7460905   13928832
 8 Americas … <NA>   2007  1594506      280163                7892712   14745322
 9 Americas … <NA>   2008  1683478      282143                7987117   14986272
10 Americas … <NA>   2009  1817143      290700                8273704   15571105
# ℹ abbreviated name: ¹​`Littered and mismanaged`

Check the Data Summary through SkimR

Check the summary through skim

skim(PlasticWasteRegion)
Data summary
Name PlasticWasteRegion
Number of rows 200
Number of columns 7
_______________________
Column type frequency:
character 2
numeric 5
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
Entity 0 1.0 5 28 0 10 0
Code 120 0.4 3 8 0 4 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
Year 0 1 2009.5 5.78 2000 2004.75 2009.5 2014.25 2019 ▇▇▇▇▇
Recycled 0 1 3469172.5 5651375.86 16475 530318.75 1605939.0 3358431.50 32829024 ▇▁▁▁▁
Incinerated 0 1 7928698.1 13050758.38 0 88523.00 1141091.5 10589305.50 67295010 ▇▁▁▁▁
Littered and mismanaged 0 1 12408734.1 17640080.50 51145 3818551.25 6189215.0 11030551.50 79329675 ▇▁▁▁▁
Landfilled 0 1 26428287.8 38588102.74 325270 3895220.50 11872016.0 30823747.00 173837392 ▇▁▁▁▁

Issues to Fix

  • Remove all unnecessary columns
  • Standardize column names
  • Filter out East/Southeast countries

Cleaning Process

Remove all unnecessary columns

PlasticWasteRegion1 <- PlasticWasteRegion |>
  select(
    Entity,
    Year,
    `Littered and mismanaged`
  )

Rename columns to cleaner names

PlasticWasteRegion2 <- PlasticWasteRegion1 |>
  rename(
    country = Entity,
    year = Year,
    mismanaged_tons = `Littered and mismanaged`
  )

Filter out East/Southeast countries

PlasticWasteRegion3 <- PlasticWasteRegion2 |>
  filter(country %in% c("Asia (excl. China and India)", "China", "India"))
glimpse(PlasticWasteRegion3)
Rows: 60
Columns: 3
$ country         <chr> "Asia (excl. China and India)", "Asia (excl. China and…
$ year            <dbl> 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, …
$ mismanaged_tons <dbl> 6400250, 6843357, 7397421, 7937021, 8544541, 9081587, …

Save cleaned Plastic Waste per Region data for later use

save(PlasticWasteRegion3, file = "out/PlasticWasteRegion_clean.RData")

3. Plastic Waste per Country Dataset Cleaning

Chack the dataset

Take a glimpse at the dataset

glimpse(PlasticWasteCountry)
Rows: 186
Columns: 4
$ Entity                                     <chr> "Albania", "Algeria", "Ango…
$ Code                                       <chr> "ALB", "DZA", "AGO", "AIA",…
$ Year                                       <dbl> 2010, 2010, 2010, 2010, 201…
$ `Per capita plastic waste (kg/person/day)` <dbl> 0.069, 0.144, 0.062, 0.252,…

Check the head of the dataset

# Check the first ten (10) rows

head(PlasticWasteCountry, 10)
# A tibble: 10 × 4
   Entity              Code   Year `Per capita plastic waste (kg/person/day)`
   <chr>               <chr> <dbl>                                      <dbl>
 1 Albania             ALB    2010                                      0.069
 2 Algeria             DZA    2010                                      0.144
 3 Angola              AGO    2010                                      0.062
 4 Anguilla            AIA    2010                                      0.252
 5 Antigua and Barbuda ATG    2010                                      0.66 
 6 Argentina           ARG    2010                                      0.183
 7 Aruba               ABW    2010                                      0.252
 8 Australia           AUS    2010                                      0.112
 9 Bahamas             BHS    2010                                      0.39 
10 Bahrain             BHR    2010                                      0.132

Check the Data Summary through SkimR

Check the summary through skim

skim(PlasticWasteCountry)
Data summary
Name PlasticWasteCountry
Number of rows 186
Number of columns 4
_______________________
Column type frequency:
character 2
numeric 2
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
Entity 0 1 4 32 0 186 0
Code 0 1 3 8 0 186 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
Year 0 1 2010.00 0.00 2010.00 2010.0 2010.00 2010.00 2010.00 ▁▁▇▁▁
Per capita plastic waste (kg/person/day) 0 1 0.18 0.12 0.01 0.1 0.14 0.25 0.69 ▇▆▁▁▁

Issues to Fix

  • Standardize column names
  • Filter out East/Southeast countries

Cleaning Process

Standardize column names

PlasticWasteCountry1 <- PlasticWasteCountry |>
  rename(
    country = Entity,
    iso_code = Code,
    year = Year,
    waste_kg_day = `Per capita plastic waste (kg/person/day)`
  )

Filter out East/Southeast countries

east_asia <- c("China", "South Korea", "North Korea", "Japan", "Hong Kong", "Taiwan")
southeast_asia <- c("Indonesia", "Malaysia", "Philippines", "Vietnam", "Thailand", "Singapore", "Cambodia", "Myanmar", "Brunei")
asia_countries <- c(east_asia, southeast_asia)

# Keep only East and Southeast Asian countries
PlasticWasteCountry2 <- PlasticWasteCountry1 |>
  filter(country %in% asia_countries)

# Assign a region label to the countries
PlasticWasteCountry3 <- PlasticWasteCountry2 |>
  mutate(
    region_group = case_when(
      country %in% east_asia ~ "East Asia",
      country %in% southeast_asia ~ "Southeast Asia",
      TRUE ~ NA_character_
    )
  )
glimpse(PlasticWasteCountry3)
Rows: 15
Columns: 5
$ country      <chr> "Brunei", "Cambodia", "China", "Hong Kong", "Indonesia", …
$ iso_code     <chr> "BRN", "KHM", "CHN", "HKG", "IDN", "JPN", "MYS", "MMR", "…
$ year         <dbl> 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 201…
$ waste_kg_day <dbl> 0.026, 0.066, 0.121, 0.398, 0.057, 0.171, 0.198, 0.075, 0…
$ region_group <chr> "Southeast Asia", "Southeast Asia", "East Asia", "East As…

Save cleaned Plastic Waste Per Country data for later use

save(PlasticWasteCountry3, file = "out/PlasticWasteCountry_clean.RData")