── 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.4.4 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── 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(here)
here() starts at /Users/lexi/Desktop/L7/Study/SAIS/Sustainable Finance - Application and Methods/Assignment/PCAF Methodology
#Tidy GHG CO2 with LULUCFpath_to_lulucf <-here("data-raw", "GHG_CO2_LULUCF_Country.xlsx")read_ghg_co2_lulucf_country_sheet <-read_excel(path = path_to_lulucf, range ="A3:AG47")read_ghg_co2_lulucf_country_sheet$`Base year`<-NULLghg_co2_lulucf_country <-pivot_longer( read_ghg_co2_lulucf_country_sheet, cols =matches("^(1|2)\\d{3}$"),names_to ="Year", values_to ="GHG CO2 with LULUCF") |>rename(Country = Party)#Tidy GHG CO2 without LULUCFpath_to_nolulucf <-here("data-raw", "GHG_CO2_Country.xlsx")read_ghg_co2_country_sheet <-read_excel(path = path_to_nolulucf, range ="A3:AG47")read_ghg_co2_country_sheet$`Base year`<-NULLghg_co2_country <-pivot_longer( read_ghg_co2_country_sheet, cols =matches("^(1|2)\\d{3}$"),names_to ="Year", values_to ="GHG CO2 without LULUCF") |>rename(Country = Party)#Combine and write the datasetsfinal_ghg_co2_country <-left_join(ghg_co2_lulucf_country, ghg_co2_country, by =c("Country", "Year"))print(final_ghg_co2_country)
# A tibble: 1,364 × 4
Country Year `GHG CO2 with LULUCF` `GHG CO2 without LULUCF`
<chr> <chr> <dbl> <dbl>
1 Australia 1990 626254. 425624.
2 Australia 1991 610773. 425686.
3 Australia 1992 546688. 429473.
4 Australia 1993 524694. 430382.
5 Australia 1994 520808. 430848.
6 Australia 1995 504057. 439270.
7 Australia 1996 510448. 445847.
8 Australia 1997 514810. 457865.
9 Australia 1998 513539. 472146.
10 Australia 1999 530836. 478137.
# ℹ 1,354 more rows