library(readr)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.3 ✓ dplyr 1.0.7
## ✓ tibble 3.1.5 ✓ stringr 1.4.0
## ✓ tidyr 1.1.4 ✓ forcats 0.5.1
## ✓ purrr 0.3.4
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
ex5 <- read_csv("IO_ex5.csv", skip = 4)
## Rows: 133 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): ctry, code, %4yr, %overwt
## dbl (3): year, gdppc, eduyr
##
## ℹ 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.
head(ex5)
## # A tibble: 6 × 7
## ctry code year gdppc eduyr `%4yr` `%overwt`
## <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr>
## 1 Afghanistan AFG 2010 1685 3.2 3.65% 16.7%
## 2 Albania ALB 2010 9272 9.3 0.93% 54.3%
## 3 Algeria DZA 2010 13092 7.1 6.66% 53.9%
## 4 Argentina ARG 2010 19068 9.8 2.87% 59.8%
## 5 Armenia ARM 2010 8079 11.1 15.03% 51.2%
## 6 Australia AUS 2010 45684 12.4 18.52% 63.9%
tail(ex5)
## # A tibble: 6 × 7
## ctry code year gdppc eduyr `%4yr` `%overwt`
## <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr>
## 1 Uruguay URY 2010 16402 8.4 3.50% 61.2%
## 2 Venezuela VEN 2010 17204 8.9 2.96% 59.3%
## 3 Vietnam VNM 2010 4555 7.5 3.27% 14.0%
## 4 Yemen YEM 2010 4811 2.6 1.50% 37.2%
## 5 Zambia ZMB 2010 3125 6.6 0.49% 20.7%
## 6 Zimbabwe ZWE 2010 1404 7.3 0.38% 29.4%
ex5 <- read_csv("IO_ex5.csv", skip = 4, col_types = cols(
ctry = col_character(),
code = col_character(),
year = col_double(),
gdppc = col_double(),
eduyr = col_double(),
`%4yr` = col_number(),
`%overwt` = col_number()
))
# we are change the column type from character to number #
head(ex5)
## # A tibble: 6 × 7
## ctry code year gdppc eduyr `%4yr` `%overwt`
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Afghanistan AFG 2010 1685 3.2 3.65 16.7
## 2 Albania ALB 2010 9272 9.3 0.93 54.3
## 3 Algeria DZA 2010 13092 7.1 6.66 53.9
## 4 Argentina ARG 2010 19068 9.8 2.87 59.8
## 5 Armenia ARM 2010 8079 11.1 15.0 51.2
## 6 Australia AUS 2010 45684 12.4 18.5 63.9
tail(ex5)
## # A tibble: 6 × 7
## ctry code year gdppc eduyr `%4yr` `%overwt`
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Uruguay URY 2010 16402 8.4 3.5 61.2
## 2 Venezuela VEN 2010 17204 8.9 2.96 59.3
## 3 Vietnam VNM 2010 4555 7.5 3.27 14
## 4 Yemen YEM 2010 4811 2.6 1.5 37.2
## 5 Zambia ZMB 2010 3125 6.6 0.49 20.7
## 6 Zimbabwe ZWE 2010 1404 7.3 0.38 29.4
library(dplyr)
colnames(ex5)
## [1] "ctry" "code" "year" "gdppc" "eduyr" "%4yr" "%overwt"
names(ex5) [names(ex5)=="%4yr"] <- "pct_college"
#this is going to be a rename of the column name #
head(ex5)
## # A tibble: 6 × 7
## ctry code year gdppc eduyr pct_college `%overwt`
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Afghanistan AFG 2010 1685 3.2 3.65 16.7
## 2 Albania ALB 2010 9272 9.3 0.93 54.3
## 3 Algeria DZA 2010 13092 7.1 6.66 53.9
## 4 Argentina ARG 2010 19068 9.8 2.87 59.8
## 5 Armenia ARM 2010 8079 11.1 15.0 51.2
## 6 Australia AUS 2010 45684 12.4 18.5 63.9
tail(ex5)
## # A tibble: 6 × 7
## ctry code year gdppc eduyr pct_college `%overwt`
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Uruguay URY 2010 16402 8.4 3.5 61.2
## 2 Venezuela VEN 2010 17204 8.9 2.96 59.3
## 3 Vietnam VNM 2010 4555 7.5 3.27 14
## 4 Yemen YEM 2010 4811 2.6 1.5 37.2
## 5 Zambia ZMB 2010 3125 6.6 0.49 20.7
## 6 Zimbabwe ZWE 2010 1404 7.3 0.38 29.4