### libraries
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
library(knitr)

### Load Data
df = read.csv("./dataset/co_e.csv", header = TRUE, sep = ",", dec = ",")

Config Data

### Config data
df = df[,-c(1:5)] # remove columns 

df =  df %>% # group data
      group_by(Flow_desc,Year) %>%
      summarise(sm = sum(Value))

import = df[38:74,] 
export = df[1:37,]
year = c(1980:2016)

df = data.frame(Years = year, Import = import$sm, Export = export$sm)

format(c(df$Import,df$Export),big.mark=".",scientific=FALSE)

Insert variables

You can also embed plots, for example:

### Insert Variation % gain
df = mutate(df, saldo = Export - Import)

Datatable

kable(df)
Years Import Export saldo
1980 641347322 481806110 -159541212
1981 1019958380 629357251 -390601129
1982 796620617 471510818 -325109799
1983 576727692 419411663 -157316029
1984 470966969 564642991 93676022
1985 654508035 577409970 -77098065
1986 913675846 746870516 -166805330
1987 826496204 755702920 -70793284
1988 974319848 849191648 -125128200
1989 1367431200 842291434 -525139766
1990 3028308416 1384961536 -1643346880
1991 3015722368 1457733088 -1557989280
1992 3366735488 1493813008 -1872922480
1993 4774348160 1465837920 -3308510240
1994 6805072768 1437612448 -5367460320
1995 10459054592 1497210048 -8961844544
1996 12111179776 1797356528 -10313823248
1997 14001304320 2100585552 -11900718768
1998 12414499584 2136689088 -10277810496
1999 11844568460 2689204574 -9155363886
2000 15202722374 4634565720 -10568156654
2001 13911328450 4800348108 -9110980342
2002 9521992246 4436748172 -5085244074
2003 9868903230 4257866046 -5611037184
2004 13801433454 4058000000 -9743433454
2005 17571111356 7444000000 -10127111356
2006 22079707734 7958000000 -14121707734
2007 24727254000 5356000000 -19371254000
2008 32604327006 6324000000 -26280327006
2009 24651603440 4680000000 -19971603440
2010 34964837560 4030000000 -30934837560
2011 40681417878 3654914000 -37026503878
2012 40114535548 2749508000 -37365027548
2013 42393280492 2397684000 -39995596492
2014 41191738606 1807882000 -39383856606
2015 29548456954 1740222000 -27808234954
2016 23958575826 1460536000 -22498039826

Plot - Balança Comercial

plot = plot(year, df$Import, type = "l", 
            main = "Balança Comercial - Brazil", 
            sub = "1980-2016",
            col = "red",
            ylab = "Valores em USD",
            xlab = "Ano")
lines(year,df$Export)