challenge8
Neha Jhurani
FAOSTAT_egg_chicken.csv, FAOSTAT_livestock.csv, FAOSTAT_cattle_dairy.csv
Author

Neha Jhurani

Published

May 12, 2023

Code
library(tidyverse)

knitr::opts_chunk$set(echo = TRUE)

Eggs / Livestock / Dairy data

Code
library(readr)

#reading FAOSTAT_egg_chicken csv data
eggs_data <- read_csv("_data/FAOSTAT_egg_chicken.csv")
Rows: 38170 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (8): Domain Code, Domain, Area, Element, Item, Unit, Flag, Flag Description
dbl (6): Area Code, Element Code, Item Code, Year Code, Year, 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.
Code
dim(eggs_data)
[1] 38170    14
Code
#extracting column names of eggs data
colnames(eggs_data)
 [1] "Domain Code"      "Domain"           "Area Code"        "Area"            
 [5] "Element Code"     "Element"          "Item Code"        "Item"            
 [9] "Year Code"        "Year"             "Unit"             "Value"           
[13] "Flag"             "Flag Description"
Code
#reading FAOSTAT_livestock csv data
livestock_data <- read_csv("_data/FAOSTAT_livestock.csv")
Rows: 82116 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (8): Domain Code, Domain, Area, Element, Item, Unit, Flag, Flag Description
dbl (6): Area Code, Element Code, Item Code, Year Code, Year, 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.
Code
dim(livestock_data)
[1] 82116    14
Code
#extracting column names of livestock data
colnames(livestock_data)
 [1] "Domain Code"      "Domain"           "Area Code"        "Area"            
 [5] "Element Code"     "Element"          "Item Code"        "Item"            
 [9] "Year Code"        "Year"             "Unit"             "Value"           
[13] "Flag"             "Flag Description"
Code
#reading FAOSTAT_cattle_diary csv data
dairy_data <- read_csv("_data/FAOSTAT_cattle_dairy.csv")
Rows: 36449 Columns: 14
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (8): Domain Code, Domain, Area, Element, Item, Unit, Flag, Flag Description
dbl (6): Area Code, Element Code, Item Code, Year Code, Year, 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.
Code
dim(dairy_data)
[1] 36449    14
Code
#extracting column names of dairy data
colnames(dairy_data)
 [1] "Domain Code"      "Domain"           "Area Code"        "Area"            
 [5] "Element Code"     "Element"          "Item Code"        "Item"            
 [9] "Year Code"        "Year"             "Unit"             "Value"           
[13] "Flag"             "Flag Description"
Code
#Joining Data

#Joining dairy and livestock data
dairy_livestock_data <- full_join(dairy_data, livestock_data)
Joining with `by = join_by(`Domain Code`, Domain, `Area Code`, Area, `Element
Code`, Element, `Item Code`, Item, `Year Code`, Year, Unit, Value, Flag, `Flag
Description`)`
Code
dim(dairy_livestock_data)
[1] 118565     14
Code
#extracting column names of combined data
colnames(dairy_livestock_data)
 [1] "Domain Code"      "Domain"           "Area Code"        "Area"            
 [5] "Element Code"     "Element"          "Item Code"        "Item"            
 [9] "Year Code"        "Year"             "Unit"             "Value"           
[13] "Flag"             "Flag Description"
Code
#Joining dairy and eggs data
dairy_eggs_data <- full_join(dairy_data, eggs_data)
Joining with `by = join_by(`Domain Code`, Domain, `Area Code`, Area, `Element
Code`, Element, `Item Code`, Item, `Year Code`, Year, Unit, Value, Flag, `Flag
Description`)`
Code
dim(dairy_eggs_data)
[1] 74619    14
Code
#extracting column names of combined data
colnames(dairy_eggs_data)
 [1] "Domain Code"      "Domain"           "Area Code"        "Area"            
 [5] "Element Code"     "Element"          "Item Code"        "Item"            
 [9] "Year Code"        "Year"             "Unit"             "Value"           
[13] "Flag"             "Flag Description"
Code
#Joining livestock and eggs data
livestock_eggs_data <- full_join(livestock_data, eggs_data)
Joining with `by = join_by(`Domain Code`, Domain, `Area Code`, Area, `Element
Code`, Element, `Item Code`, Item, `Year Code`, Year, Unit, Value, Flag, `Flag
Description`)`
Code
dim(livestock_eggs_data)
[1] 120286     14
Code
#extracting column names of combined data
colnames(livestock_eggs_data)
 [1] "Domain Code"      "Domain"           "Area Code"        "Area"            
 [5] "Element Code"     "Element"          "Item Code"        "Item"            
 [9] "Year Code"        "Year"             "Unit"             "Value"           
[13] "Flag"             "Flag Description"