REQUIRED PACKAGES

library(readxl)
library(tidyverse)
## ── Attaching packages ───────────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.2.1     ✔ purrr   0.3.2
## ✔ tibble  2.1.3     ✔ dplyr   0.8.3
## ✔ tidyr   1.0.0     ✔ stringr 1.4.0
## ✔ readr   1.3.1     ✔ forcats 0.4.0
## ── Conflicts ──────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(splitstackshape)

REQUIRED DATA BIND FUNCTION FOR DATAFRAME BINDING ()

force_bind = function(df1, df2) {
colnames(df2) = colnames(df1)
bind_rows(df1, df2) }

Raw Datas are gathered from provided link; link

2012 Data Set

imp_2012 <-read_xlsx("/Users/ozgunkurt/Desktop/Fınal/2012 Yılı İthalat Verileri.xlsx",skip = 3)
imp_2012$`Miktarı(Kg)` <- as.numeric(as.character(imp_2012$`Miktarı(Kg)`))
## Warning: NAs introduced by coercion
df_2 <- cSplit(imp_2012, 3:ncol(imp_2012), sep=",", stripWhite=TRUE, type.convert=FALSE)
df_2$country_count <- (9-apply(is.na(df_2), 1, sum))
df_2 <- select(df_2, length(df_2))
imp_2012 <- cbind(imp_2012,df_2)
imp_2012$Year <-2012

2013 Data Set

imp_2013 <- read_xlsx("/Users/ozgunkurt/Desktop/Fınal/2013 Yılı İthalat Verileri.xlsx",skip = 3)
imp_2013$`Miktarı(Kg)` <- as.numeric(as.character(imp_2013$`Miktarı(Kg)`))
df_3 <- cSplit(imp_2013, 3:ncol(imp_2013), sep=",", stripWhite=TRUE, type.convert=FALSE)
df_3$country_count <- (6-apply(is.na(df_3), 1, sum))
df_3 <- select(df_3, length(df_3))
imp_2013 <- cbind(imp_2013,df_3)
imp_2013$Year <-2013

2014 Data Set

imp_2014 <- read_xlsx("/Users/ozgunkurt/Desktop/Fınal/2014 Yılı Organik Tarım İthalatı.xlsx",skip =1)
imp_2014$`Miktarı(Kg)` <- as.numeric(as.character(imp_2014$`Miktarı(Kg)`))
df_4 <- cSplit(imp_2014, 3:ncol(imp_2014), sep=",", stripWhite=TRUE, type.convert=FALSE)
df_4$country_count <- (5-apply(is.na(df_4), 1, sum))
df_4 <- select(df_4, length(df_4))
imp_2014 <- cbind(imp_2014,df_4)
imp_2014$Year <-2014
exp_2014 <- read_xlsx("/Users/ozgunkurt/Desktop/Fınal/2014 Organik Ürün İhracat İstatistikleri.xlsx")
exp_2014$Year <-2014

2015 Data Set

imp_2015 <- read_xlsx("/Users/ozgunkurt/Desktop/Fınal/2015 Yılı İthalat Verileri.xlsx",skip=1)
imp_2015$`Miktarı(Kg)` <- as.numeric(as.character(imp_2015$`Miktarı(Kg)`))
df_5 <- cSplit(imp_2015, 3:ncol(imp_2015), sep=",", stripWhite=TRUE, type.convert=FALSE)
df_5$country_count <- (5-apply(is.na(df_5), 1, sum))
df_5 <- select(df_5, length(df_5))
imp_2015 <- cbind(imp_2015,df_5)
imp_2015$Year <-2015
exp_2015 <- read_xlsx("/Users/ozgunkurt/Desktop/Fınal/2015 Yılı  İhracat Verileri.xlsx",skip = 1)
exp_2015$Year <-2015

2016 Data Set

imp_2016 <- read_xlsx("/Users/ozgunkurt/Desktop/Fınal/2016 Yılı İthalat Verileri.xlsx",skip=1)
imp_2016$`Miktarı(Kg)` <- as.numeric(as.character(imp_2016$`Miktarı(Kg)`))
df_6 <- cSplit(imp_2016, 3:ncol(imp_2016), sep=",", stripWhite=TRUE, type.convert=FALSE)
df_6$country_count <- (5-apply(is.na(df_6), 1, sum))
df_6 <- select(df_6, length(df_6))
imp_2016 <- cbind(imp_2016,df_6)
imp_2016$Year <-2016
exp_2016 <- read_xlsx("/Users/ozgunkurt/Desktop/Fınal/2016 ihracat verileri.xlsx",skip = 2)
exp_2016$Year <-2016

2017 Data Set

imp_2017 <- read_xlsx("/Users/ozgunkurt/Desktop/Fınal/2017 yılı İthalat Verileri.xlsx",skip=1)
imp_2017$`Miktarı(Kg)` <- as.numeric(as.character(imp_2017$`Miktarı(Kg)`))
df_7 <- cSplit(imp_2017, 3:ncol(imp_2017), sep=",", stripWhite=TRUE, type.convert=FALSE)
df_7$country_count <- (7-apply(is.na(df_7), 1, sum))
df_7 <- select(df_7, length(df_7))
imp_2017 <- cbind(imp_2017,df_7)
imp_2017$Year <-2017
exp_2017 <- read_xlsx("/Users/ozgunkurt/Desktop/Fınal/2017 Yılı İhracat Verileri.xlsx",skip=1)
exp_2017$Year <-2017

2018 Data Set

imp_2018 <- read_xlsx("/Users/ozgunkurt/Desktop/Fınal/2018 yılı İthalat Verileri.xlsx",skip=1)
imp_2018$`Miktarı(Kg)` <- as.numeric(as.character(imp_2018$`Miktarı(Kg)`))
df_8 <- cSplit(imp_2018, 3:ncol(imp_2018), sep=",", stripWhite=TRUE, type.convert=FALSE)
df_8$country_count <- (13-apply(is.na(df_8), 1, sum))
df_8 <- select(df_8, length(df_8))
imp_2018 <- cbind(imp_2018,df_8)
imp_2018$Year <-2018
exp_2018 <- read_xlsx("/Users/ozgunkurt/Desktop/Fınal/2018 Yılı İhracat Verileri.xlsx",skip=1)
exp_2018$Year <-2018

BINDING ALL YEAR DATASETS TOGETHER

imp_total <- force_bind(imp_2012,imp_2013)
imp_total <- force_bind(imp_total,imp_2014)
imp_total <- force_bind(imp_total,imp_2015)
imp_total <- force_bind(imp_total,imp_2016)
imp_total <- force_bind(imp_total,imp_2017)
imp_total <- force_bind(imp_total,imp_2018)

exp_total <- force_bind(exp_2014,exp_2015)
exp_total <- force_bind(exp_total,exp_2016)
exp_total <- force_bind(exp_total,exp_2017)
exp_total <- force_bind(exp_total,exp_2018)

CREATING DATA AS RDATA FORMAT

save(exp_total, imp_total, file = "imp_exp_total.RData")

HAVE A LOOK AT DATA

glimpse(exp_total)
## Observations: 67
## Variables: 3
## $ ÜRÜN         <chr> "İNCİR VE İNCİR ÜRÜNLERİ", "FINDIK VE FINDIK ÜRÜNLE…
## $ `MİKTAR(kg)` <dbl> 4523936, 1642488, 4118835, 1975009, 1292370, 132447…
## $ Year         <dbl> 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 201…

OTHER AGRICULTURE DATAS WHICH ARE CREATED BY SAME APPROACH

Agricultural_Data

BINDED ALL AGRICULTURAL DATA BDA_503_FINAL_AGRICULTURAL