Warning: There were 2 warnings in `mutate()`.
The first warning was:
ℹ In argument: `country_name = countrycode(sourcevar = Name, origin =
"country.name", destination = "country.name")`.
Caused by warning:
! Some values were not matched unambiguously: Int. Aviation, Int. Shipping, Virgin Islands_USA
ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
# Dynamically select year columns if they follow a specific naming pattern (e.g., are numeric)year_cols <-grep("^[0-9]{4}$", names(EDGAR_GHG_data), value =TRUE)EDGAR_GHG_data_long <- EDGAR_GHG_data %>%pivot_longer(cols =all_of(year_cols), # Use all_of() to pivot only the year columns identified abovenames_to ="year",values_to ="value" ) %>%mutate(year =as.integer(year), # Convert year to integerEDGAR_GHG_value =as.numeric(value) # Convert value to numeric if not already )
Warning: There were 2 warnings in `mutate()`.
The first warning was:
ℹ In argument: `country_name = countrycode(sourcevar = Name, origin =
"country.name", destination = "country.name")`.
Caused by warning:
! Some values were not matched unambiguously: Asia-Pacific Economic Cooperation, Association of South East Asian Nations, East and Southeastern Asia, Eastern Asia, EU28 excluding EU15, Euro area (19 countries), Europe, European Union (15 countries), European Union (27 countries), European Union (28 countries), Group of Twenty, Non-OECD economies and aggregates, North America, OECD member countries, Other regions, Rest of the World, South and Central America, World
ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
# Dynamically select year columns if they follow a specific naming pattern (e.g., are numeric)year_cols <-grep("^[0-9]{4}$", names(OECD_exports_data), value =TRUE)OECD_exports_data_long <-OECD_exports_data %>%pivot_longer(cols =all_of(year_cols), # Use all_of() to pivot only the year columns identified abovenames_to ="year",values_to ="value" ) %>%mutate(year =as.integer(year), # Convert year to integerOECD_exports_value =as.numeric(value) # Convert value to numeric if not already )
Warning: There were 2 warnings in `mutate()`.
The first warning was:
ℹ In argument: `country_name = countrycode(sourcevar = Name, origin =
"country.name", destination = "country.name")`.
Caused by warning:
! Some values were not matched unambiguously: Asia-Pacific Economic Cooperation, Association of South East Asian Nations, Eastern Asia, EU28 excluding EU15, Euro area (19 countries), European Union (15 countries), European Union (27 countries), European Union (28 countries), Group of Twenty, Non-OECD economies and aggregates, OECD member countries, Rest of the World
ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
year_cols <-grep("^[0-9]{4}$", names(OECD_nonenergy_import_data), value =TRUE)OECD_nonenergy_import_data_long <-OECD_nonenergy_import_data %>%pivot_longer(cols =all_of(year_cols), # Use all_of() to pivot only the year columns identified abovenames_to ="year",values_to ="value" ) %>%mutate(year =as.integer(year), # Convert year to integerOECD_non_energy_import =as.numeric(value) # Convert value to numeric if not already )
Warning: There were 2 warnings in `mutate()`.
The first warning was:
ℹ In argument: `country_name = countrycode(sourcevar = Name, origin =
"country.name", destination = "country.name")`.
Caused by warning:
! Some values were not matched unambiguously: Asia-Pacific Economic Cooperation, Association of South East Asian Nations, Eastern Asia, EU28 excluding EU15, Euro area (19 countries), European Union (15 countries), European Union (27 countries), European Union (28 countries), Group of Twenty, Non-OECD economies and aggregates, OECD member countries, Rest of the World
ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
year_cols <-grep("^[0-9]{4}$", names(OECD_D35_import_data), value =TRUE)OECD_D35_import_data_long <-OECD_D35_import_data %>%pivot_longer(cols =all_of(year_cols), # Use all_of() to pivot only the year columns identified abovenames_to ="year",values_to ="value" ) %>%mutate(year =as.integer(year), # Convert year to integerOECD_D35_import_data =as.numeric(value) # Convert value to numeric if not already )
Warning: There were 2 warnings in `mutate()`.
The first warning was:
ℹ In argument: `country_name = countrycode(sourcevar = Name, origin =
"country.name", destination = "country.name")`.
Caused by warning:
! Some values were not matched unambiguously: Africa Eastern and Southern, Africa Western and Central, Arab World, Caribbean small states, Central Europe and the Baltics, Early-demographic dividend, East Asia & Pacific, East Asia & Pacific (excluding high income), East Asia & Pacific (IDA & IBRD countries), Euro area, Europe & Central Asia, Europe & Central Asia (excluding high income), Europe & Central Asia (IDA & IBRD countries), European Union, Fragile and conflict affected situations, Heavily indebted poor countries (HIPC), High income, IBRD only, IDA & IBRD total, IDA blend, IDA only, IDA total, Late-demographic dividend, Latin America & Caribbean, Latin America & Caribbean (excluding high income), Latin America & the Caribbean (IDA & IBRD countries), Least developed countries: UN classification, Low & middle income, Low income, Lower middle income, Middle East & North Africa, Middle East & North Africa (excluding high income), Middle East & North Africa (IDA & IBRD countries), Middle income, North America, Not classified, OECD members, Other small states, Pacific island small states, Post-demographic dividend, Pre-demographic dividend, Small states, South Asia, South Asia (IDA & IBRD), Sub-Saharan Africa, Sub-Saharan Africa (excluding high income), Sub-Saharan Africa (IDA & IBRD countries), Upper middle income, World
ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
year_cols <-grep("^[0-9]{4}$", names(GDP_adjusted_PPP), value =TRUE)GDP_adjusted_PPP_long <-GDP_adjusted_PPP %>%pivot_longer(cols =all_of(year_cols), # Use all_of() to pivot only the year columns identified abovenames_to ="year",values_to ="value" ) %>%mutate(year =as.integer(year), # Convert year to integerGDP_adjusted_PPP =as.numeric(value) # Convert value to numeric if not already )
Warning: There were 2 warnings in `mutate()`.
The first warning was:
ℹ In argument: `country_name = countrycode(sourcevar = Name, origin =
"country.name", destination = "country.name")`.
Caused by warning:
! Some values were not matched unambiguously: Africa Eastern and Southern, Africa Western and Central, Arab World, Caribbean small states, Central Europe and the Baltics, Early-demographic dividend, East Asia & Pacific, East Asia & Pacific (excluding high income), East Asia & Pacific (IDA & IBRD countries), Euro area, Europe & Central Asia, Europe & Central Asia (excluding high income), Europe & Central Asia (IDA & IBRD countries), European Union, Fragile and conflict affected situations, Heavily indebted poor countries (HIPC), High income, IBRD only, IDA & IBRD total, IDA blend, IDA only, IDA total, Late-demographic dividend, Latin America & Caribbean, Latin America & Caribbean (excluding high income), Latin America & the Caribbean (IDA & IBRD countries), Least developed countries: UN classification, Low & middle income, Low income, Lower middle income, Middle East & North Africa, Middle East & North Africa (excluding high income), Middle East & North Africa (IDA & IBRD countries), Middle income, North America, Not classified, OECD members, Other small states, Pacific island small states, Post-demographic dividend, Pre-demographic dividend, Small states, South Asia, South Asia (IDA & IBRD), Sub-Saharan Africa, Sub-Saharan Africa (excluding high income), Sub-Saharan Africa (IDA & IBRD countries), Upper middle income, World
ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
year_cols <-grep("^[0-9]{4}$", names(GDP_current_dollar), value =TRUE)GDP_current_dollar_long <-GDP_current_dollar %>%pivot_longer(cols =all_of(year_cols), # Use all_of() to pivot only the year columns identified abovenames_to ="year",values_to ="value" ) %>%mutate(year =as.integer(year), # Convert year to integerGDP_current_dollar =as.numeric(value) # Convert value to numeric if not already )
library(tidyverse) library(readxl) library(here) library(countrycode)path_to_sheet7 <-"C:/Users/puxin/OneDrive/Documents/PCAF-data-raw/population.xlsx"# Attempt to read the file againpopulation <-read_excel(path_to_sheet7, range ="A1:BM267")population <- population %>%mutate(country_name =countrycode(sourcevar = Name, origin ="country.name", destination ="country.name"),iso3c =countrycode(sourcevar = Name, origin ="country.name", destination ="iso3c") )
Warning: There were 2 warnings in `mutate()`.
The first warning was:
ℹ In argument: `country_name = countrycode(sourcevar = Name, origin =
"country.name", destination = "country.name")`.
Caused by warning:
! Some values were not matched unambiguously: Africa Eastern and Southern, Africa Western and Central, Arab World, Caribbean small states, Central Europe and the Baltics, Early-demographic dividend, East Asia & Pacific, East Asia & Pacific (excluding high income), East Asia & Pacific (IDA & IBRD countries), Euro area, Europe & Central Asia, Europe & Central Asia (excluding high income), Europe & Central Asia (IDA & IBRD countries), European Union, Fragile and conflict affected situations, Heavily indebted poor countries (HIPC), High income, IBRD only, IDA & IBRD total, IDA blend, IDA only, IDA total, Late-demographic dividend, Latin America & Caribbean, Latin America & Caribbean (excluding high income), Latin America & the Caribbean (IDA & IBRD countries), Least developed countries: UN classification, Low & middle income, Low income, Lower middle income, Middle East & North Africa, Middle East & North Africa (excluding high income), Middle East & North Africa (IDA & IBRD countries), Middle income, North America, Not classified, OECD members, Other small states, Pacific island small states, Post-demographic dividend, Pre-demographic dividend, Small states, South Asia, South Asia (IDA & IBRD), Sub-Saharan Africa, Sub-Saharan Africa (excluding high income), Sub-Saharan Africa (IDA & IBRD countries), Upper middle income, World
ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
year_cols <-grep("^[0-9]{4}$", names(population), value =TRUE)population_long <-population %>%pivot_longer(cols =all_of(year_cols), # Use all_of() to pivot only the year columns identified abovenames_to ="year",values_to ="value" ) %>%mutate(year =as.integer(year), # Convert year to integerpopulation =as.numeric(value) # Convert value to numeric if not already )
library(dplyr)library(readr)# Selecting specific columns from the first datasetEDGAR_GHG_selected <- EDGAR_GHG_data_long %>%select(Name, year, EDGAR_GHG_value)# Selecting specific columns from the second datasetOECD_exports_selected <- OECD_exports_data_long %>%select(Name, year, OECD_exports_value)# Merging the selected columns from the two datasetsmerged_data <-full_join(EDGAR_GHG_selected, OECD_exports_selected, by =c("Name", "year"))OECD_nonenergy_import_selected <- OECD_nonenergy_import_data_long %>%select(Name, year, OECD_non_energy_import)# Merging it into the existing merged_datamerged_data <-full_join(merged_data, OECD_nonenergy_import_selected, by =c("Name", "year"))OECD_D35_import_selected <- OECD_D35_import_data_long %>%select(Name, year, OECD_D35_import_data)merged_data <-full_join(merged_data, OECD_D35_import_selected, by =c("Name", "year"))# Continue with GDP adjusted for PPPGDP_adjusted_PPP_selected <- GDP_adjusted_PPP_long %>%select(Name, year, GDP_adjusted_PPP)merged_data <-full_join(merged_data, GDP_adjusted_PPP_selected, by =c("Name", "year"))# Continue with GDP in current dollarsGDP_current_dollar_selected <- GDP_current_dollar_long %>%select(Name, year, GDP_current_dollar)merged_data <-full_join(merged_data, GDP_current_dollar_selected, by =c("Name", "year"))# Continue with population datapopulation_selected <- population_long %>%select(Name, year, population)merged_data <-full_join(merged_data, population_selected, by =c("Name", "year"))# Assuming merged_data is your final datasetPCAF_data_final <- merged_data# Specify the file path and name for the final CSVfinal_csv_path <-"PCAF-data-final.csv"# Adjust the path as needed# Save the final dataset to a CSV filewrite_csv(PCAF_data_final, final_csv_path)