library(rio)

#Importando todas las datas

library(readr)
Broadband_fixed_subscriptions <- read_csv("Broadband - fixed subscriptions.csv")
## Rows: 214 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (2): date_of_information, ranking
## num (1): 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.
View(Broadband_fixed_subscriptions)
Carbon_dioxide_emissions <- read_csv("Carbon dioxide emissions.csv")
## Rows: 218 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (2): date_of_information, ranking
## num (1): metric tonnes of CO2
## 
## ℹ 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.
View(Carbon_dioxide_emissions)

Debt_external <- read_csv("Debt - external.csv")
## Rows: 207 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): name, slug, value, date_of_information, region
## dbl (1): ranking
## 
## ℹ 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.
View(Debt_external)

Electricity_installed_generating_capacity <- read_csv("Electricity - installed generating capacity.csv")
## Rows: 213 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (2): date_of_information, ranking
## num (1): kW
## 
## ℹ 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.
View(Electricity_installed_generating_capacity)

Energy_consumption_per_capita <- read_csv("Energy consumption per capita.csv")
## Rows: 212 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (2): date_of_information, ranking
## num (1): Btu/person
## 
## ℹ 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.
View(Energy_consumption_per_capita)

Inflation_rate_consumer_prices_ <- read_csv("Inflation rate (consumer prices).csv")
## Rows: 221 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): name, slug, date_of_information, region
## dbl (1): ranking
## num (1): %
## 
## ℹ 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.
View(Inflation_rate_consumer_prices_)

Public_debt <- read_csv("Public debt.csv")
## Rows: 210 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): name, slug, date_of_information, region
## dbl (2): % of GDP, ranking
## 
## ℹ 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.
View(Public_debt)

Refined_petroleum_products_production <- read_csv("Refined petroleum products - production.csv")
## Rows: 216 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (2): date_of_information, ranking
## num (1): bbl/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.
View(Refined_petroleum_products_production)

Telephones_fixed_lines <- read_csv("Telephones - fixed lines.csv")
## Rows: 224 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (2): date_of_information, ranking
## num (1): 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.
View(Telephones_fixed_lines)

Telephones_mobile_cellular <- read_csv("Telephones - mobile cellular.csv")
## Rows: 225 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (2): date_of_information, ranking
## num (1): 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.
View(Telephones_mobile_cellular)

Youth_unemployment_rate_ages_15_24_ <- read_csv("Youth unemployment rate (ages 15-24).csv")
## Rows: 203 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): name, slug, region
## dbl (3): %, date_of_information, ranking
## 
## ℹ 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.
View(Youth_unemployment_rate_ages_15_24_)

#Limpieza

Broadband_fixed_subscriptions <- Broadband_fixed_subscriptions[, !(names(Broadband_fixed_subscriptions) %in% "slug")]
Carbon_dioxide_emissions <- Carbon_dioxide_emissions[, !(names(Carbon_dioxide_emissions) %in% "slug")]
Debt_external <- Debt_external[, !(names(Debt_external) %in% "slug")]
Electricity_installed_generating_capacity <- Electricity_installed_generating_capacity[, !(names(Electricity_installed_generating_capacity) %in% "slug")]
Energy_consumption_per_capita <- Energy_consumption_per_capita[, !(names(Energy_consumption_per_capita) %in% "slug")]
Inflation_rate_consumer_prices_ <- Inflation_rate_consumer_prices_[, !(names(Inflation_rate_consumer_prices_) %in% "slug")]
Public_debt <- Public_debt[, !(names(Public_debt) %in% "slug")]
Refined_petroleum_products_production <- Refined_petroleum_products_production[, !(names(Refined_petroleum_products_production) %in% "slug")]
Telephones_fixed_lines <- Telephones_fixed_lines[, !(names(Telephones_fixed_lines) %in% "slug")]
Telephones_mobile_cellular <- Telephones_mobile_cellular[, !(names(Telephones_mobile_cellular) %in% "slug")]
Youth_unemployment_rate_ages_15_24_ <- Youth_unemployment_rate_ages_15_24_[, !(names(Youth_unemployment_rate_ages_15_24_) %in% "slug")]
Broadband_fixed_subscriptions <- Broadband_fixed_subscriptions[, !(names(Broadband_fixed_subscriptions) %in% "region")]
Carbon_dioxide_emissions <- Carbon_dioxide_emissions[, !(names(Carbon_dioxide_emissions) %in% "region")]
Debt_external <- Debt_external[, !(names(Debt_external) %in% "region")]
Electricity_installed_generating_capacity <- Electricity_installed_generating_capacity[, !(names(Electricity_installed_generating_capacity) %in% "region")]
Energy_consumption_per_capita <- Energy_consumption_per_capita[, !(names(Energy_consumption_per_capita) %in% "region")]
Inflation_rate_consumer_prices_ <- Inflation_rate_consumer_prices_[, !(names(Inflation_rate_consumer_prices_) %in% "region")]
Public_debt <- Public_debt[, !(names(Public_debt) %in% "region")]
Refined_petroleum_products_production <- Refined_petroleum_products_production[, !(names(Refined_petroleum_products_production) %in% "region")]
Telephones_fixed_lines <- Telephones_fixed_lines[, !(names(Telephones_fixed_lines) %in% "region")]
Telephones_mobile_cellular <- Telephones_mobile_cellular[, !(names(Telephones_mobile_cellular) %in% "region")]
Youth_unemployment_rate_ages_15_24_ <- Youth_unemployment_rate_ages_15_24_[, !(names(Youth_unemployment_rate_ages_15_24_) %in% "region")]
Broadband_fixed_subscriptions <- Broadband_fixed_subscriptions[, !(names(Broadband_fixed_subscriptions) %in% "ranking")]
Carbon_dioxide_emissions <- Carbon_dioxide_emissions[, !(names(Carbon_dioxide_emissions) %in% "ranking")]
Debt_external <- Debt_external[, !(names(Debt_external) %in% "ranking")]
Electricity_installed_generating_capacity <- Electricity_installed_generating_capacity[, !(names(Electricity_installed_generating_capacity) %in% "ranking")]
Energy_consumption_per_capita <- Energy_consumption_per_capita[, !(names(Energy_consumption_per_capita) %in% "ranking")]
Inflation_rate_consumer_prices_ <- Inflation_rate_consumer_prices_[, !(names(Inflation_rate_consumer_prices_) %in% "ranking")]
Public_debt <- Public_debt[, !(names(Public_debt) %in% "ranking")]
Refined_petroleum_products_production <- Refined_petroleum_products_production[, !(names(Refined_petroleum_products_production) %in% "ranking")]
Telephones_fixed_lines <- Telephones_fixed_lines[, !(names(Telephones_fixed_lines) %in% "ranking")]
Telephones_mobile_cellular <- Telephones_mobile_cellular[, !(names(Telephones_mobile_cellular) %in% "ranking")]
Youth_unemployment_rate_ages_15_24_ <- Youth_unemployment_rate_ages_15_24_[, !(names(Youth_unemployment_rate_ages_15_24_) %in% "ranking")]
Broadband_fixed_subscriptions <- Broadband_fixed_subscriptions[, !(names(Broadband_fixed_subscriptions) %in% "date_of_information")]
Carbon_dioxide_emissions <- Carbon_dioxide_emissions[, !(names(Carbon_dioxide_emissions) %in% "date_of_information")]
Debt_external <- Debt_external[, !(names(Debt_external) %in% "date_of_information")]
Electricity_installed_generating_capacity <- Electricity_installed_generating_capacity[, !(names(Electricity_installed_generating_capacity) %in% "date_of_information")]
Energy_consumption_per_capita <- Energy_consumption_per_capita[, !(names(Energy_consumption_per_capita) %in% "date_of_information")]
Inflation_rate_consumer_prices_ <- Inflation_rate_consumer_prices_[, !(names(Inflation_rate_consumer_prices_) %in% "date_of_information")]
Public_debt <- Public_debt[, !(names(Public_debt) %in% "date_of_information")]
Refined_petroleum_products_production <- Refined_petroleum_products_production[, !(names(Refined_petroleum_products_production) %in% "date_of_information")]
Telephones_fixed_lines <- Telephones_fixed_lines[, !(names(Telephones_fixed_lines) %in% "date_of_information")]
Telephones_mobile_cellular <- Telephones_mobile_cellular[, !(names(Telephones_mobile_cellular) %in% "date_of_information")]
Youth_unemployment_rate_ages_15_24_ <- Youth_unemployment_rate_ages_15_24_[, !(names(Youth_unemployment_rate_ages_15_24_) %in% "date_of_information")]

#Uniendo las datas

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
lista_dataframes <- list(Broadband_fixed_subscriptions, Carbon_dioxide_emissions, Debt_external, Electricity_installed_generating_capacity, Energy_consumption_per_capita, Inflation_rate_consumer_prices_, Public_debt, Refined_petroleum_products_production, Telephones_fixed_lines, Telephones_mobile_cellular, Youth_unemployment_rate_ages_15_24_)

dataunida <- Reduce(function(x, y) full_join(x, y, by = "name"), lista_dataframes)
print(dataunida)
## # A tibble: 231 × 12
##    name         value.x `metric tonnes of CO2` value.y     kW `Btu/person` `%.x`
##    <chr>          <dbl>                  <dbl> <chr>    <dbl>        <dbl> <dbl>
##  1 China         4.84e8            10773248000 $2,027… 2.22e9    105687000  1.97
##  2 United Stat…  1.21e8             5144361000 $20,27… 1.14e9    304414000  8   
##  3 Japan         4.40e7             1103234000 $4,254… 3.49e8    147107000  2.5 
##  4 Brazil        3.63e7              456670000 $681,3… 1.95e8     59444000  9.28
##  5 Germany       3.62e7              726881000 $5,671… 2.48e8    161174000  6.87
##  6 Russia        3.39e7             1848070000 $479,8… 2.76e8    227898000  6.69
##  7 France        3.06e7              338425000 $6,356… 1.39e8    151053000  5.22
##  8 United King…  2.73e7              398084000 $8,722… 1.13e8    119894000  7.92
##  9 India         2.29e7             2314738000 $555,3… 4.33e8     23231000  6.7 
## 10 Korea, South  2.23e7              686954000 $457,7… 1.36e8    242346000  5.09
## # ℹ 221 more rows
## # ℹ 5 more variables: `% of GDP` <dbl>, `bbl/day` <dbl>, value.x.x <dbl>,
## #   value.y.y <dbl>, `%.y` <dbl>
dataunida <- Reduce(function(x, y) full_join(x, y, by = "name"), lista_dataframes)

#PREGUNTA 1 (AF) #####—-

#PREGUNTA 2