library(readr)
library(readxl)
setwd("C:/Users/USER/Downloads/Taller3_M2_U4")
getwd()
## [1] "C:/Users/USER/Downloads/Taller3_M2_U4"
base1<- read_delim("paises1.csv", delim = ";")
## Rows: 140 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ";"
## chr (3): country, region, income_level
## dbl (3): income, life_exp, 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.
base2<- read_excel("paises2.xlsx", sheet = "paises2")
head(base1)
## # A tibble: 6 × 6
## country region income income_level life_exp co2
## <chr> <chr> <dbl> <chr> <dbl> <dbl>
## 1 Afghanistan Asia 3 Level 1 63 1
## 2 Albania Europe 14 Level 3 79 2
## 3 Algeria Africa 12 Level 3 76 4
## 4 Andorra Europe 59 Level 4 83 7
## 5 Angola Africa 7 Level 2 65 2
## 6 Antigua and Barbuda Americas 21 Level 3 77 6
head(base2)
## # A tibble: 6 × 6
## country region income income_level `94` co2
## <chr> <chr> <dbl> <chr> <dbl> <dbl>
## 1 Romania Europe 80 Level 4 68 95
## 2 Russia Europe 96 Level 4 82 95
## 3 Rwanda Africa 69 Level 1 79 84
## 4 Samoa Asia 144 Level 2 79 95
## 5 Sao Tome and Principe Africa 131 Level 2 70 90
## 6 Saudi Arabia Asia 85 Level 4 94 90
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
base_fusion<- full_join(base1, base2, by="region")
## Warning in full_join(base1, base2, by = "region"): Detected an unexpected many-to-many relationship between `x` and `y`.
## ℹ Row 1 of `x` matches multiple rows in `y`.
## ℹ Row 1 of `y` matches multiple rows in `x`.
## ℹ If a many-to-many relationship is expected, set `relationship =
## "many-to-many"` to silence this warning.
head(base_fusion)
## # A tibble: 6 × 11
## country.x region income.x income_level.x life_exp co2.x country.y income.y
## <chr> <chr> <dbl> <chr> <dbl> <dbl> <chr> <dbl>
## 1 Afghanistan Asia 3 Level 1 63 1 Samoa 144
## 2 Afghanistan Asia 3 Level 1 63 1 Saudi Arab… 85
## 3 Afghanistan Asia 3 Level 1 63 1 Singapore 117
## 4 Afghanistan Asia 3 Level 1 63 1 Solomon Is… 90
## 5 Afghanistan Asia 3 Level 1 63 1 South Korea 94
## 6 Afghanistan Asia 3 Level 1 63 1 Sri Lanka 117
## # ℹ 3 more variables: income_level.y <chr>, `94` <dbl>, co2.y <dbl>
## [1] 1935 11
## # A tibble: 6 × 11
## country.x region income.x income_level.x life_exp co2.x country.y income.y
## <chr> <chr> <dbl> <chr> <dbl> <dbl> <chr> <dbl>
## 1 Afghanistan Asia 3 Level 1 63 1 Samoa 144
## 2 Afghanistan Asia 3 Level 1 63 1 Saudi Arab… 85
## 3 Afghanistan Asia 3 Level 1 63 1 Singapore 117
## 4 Afghanistan Asia 3 Level 1 63 1 Solomon Is… 90
## 5 Afghanistan Asia 3 Level 1 63 1 South Korea 94
## 6 Afghanistan Asia 3 Level 1 63 1 Sri Lanka 117
## # ℹ 3 more variables: income_level.y <chr>, `94` <dbl>, co2.y <dbl>
## # A tibble: 6 × 11
## country.x region income.x income_level.x life_exp co2.x country.y income.y
## <chr> <chr> <dbl> <chr> <dbl> <dbl> <chr> <dbl>
## 1 Qatar Asia 91 Level 4 77 38 Tuvalu 80
## 2 Qatar Asia 91 Level 4 77 38 United Arab … 130
## 3 Qatar Asia 91 Level 4 77 38 Uzbekistan 99
## 4 Qatar Asia 91 Level 4 77 38 Vanuatu 149
## 5 Qatar Asia 91 Level 4 77 38 Vietnam 90
## 6 Qatar Asia 91 Level 4 77 38 Yemen 107
## # ℹ 3 more variables: income_level.y <chr>, `94` <dbl>, co2.y <dbl>
## spc_tbl_ [1,935 × 11] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ country.x : chr [1:1935] "Afghanistan" "Afghanistan" "Afghanistan" "Afghanistan" ...
## $ region : chr [1:1935] "Asia" "Asia" "Asia" "Asia" ...
## $ income.x : num [1:1935] 3 3 3 3 3 3 3 3 3 3 ...
## $ income_level.x: chr [1:1935] "Level 1" "Level 1" "Level 1" "Level 1" ...
## $ life_exp : num [1:1935] 63 63 63 63 63 63 63 63 63 63 ...
## $ co2.x : num [1:1935] 1 1 1 1 1 1 1 1 1 1 ...
## $ country.y : chr [1:1935] "Samoa" "Saudi Arabia" "Singapore" "Solomon Islands" ...
## $ income.y : num [1:1935] 144 85 117 90 94 117 86 101 108 77 ...
## $ income_level.y: chr [1:1935] "Level 2" "Level 4" "Level 4" "Level 2" ...
## $ 94 : num [1:1935] 79 94 86 71 92 86 64 67 88 77 ...
## $ co2.y : num [1:1935] 95 90 92 96 85 88 93 91 89 87 ...
## - attr(*, "spec")=
## .. cols(
## .. country = col_character(),
## .. region = col_character(),
## .. income = col_double(),
## .. income_level = col_character(),
## .. life_exp = col_double(),
## .. co2 = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
##
## 1 2 3 4 5 6 7 8 9 10 11 14 15 16 17 18 19 20 24 38
## 558 328 234 120 99 79 66 79 116 63 11 38 11 19 19 19 19 19 19 19
##
## 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
## 78 153 251 66 134 40 40 153 147 214 152 61 147 80 106 73 40
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.