select_main_partners: A function to select main partner(s) for each reporter

Description Usage Arguments Value Examples

View source: R/select_main_partners.R

Description

select_wood_imports selects trade flows for the product code of interest and its parents.

Select the largest country pairs Select all country pairs which represent at least a given percentage (default to 1

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
select_main_partners(df, slice_n = 1)

select_wood_imports(
  wood_imports,
  partner_codes_of_interest,
  product_codes_of_interest
)

select_large_country_pairs(df, trade_pc_threshold = 0.01)

display_table_percentage(
  df_large_country_pairs,
 
    caption = "Percentage of trade value in the main country pairs compared to trade in all countries"
)

display_table_number_of_flows(
  df_large_country_pairs,
  caption = "Number of trade flows in the main country pairs"
)

Arguments

df

a data frame of trade flows

slice_n

vector of partner(s) to slice, defaults to one

df_large_country_pairs

a data frame of main partners with columns 'trade_pct' and 'n'. output of the select_large_country_pairs function.

caption

character table caption

Value

a data frame with the main partner for each reporter

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## Not run: 
library(dplyr)
# Load sawnwood oak data from the database
con <- RMariaDB::dbConnect(RMariaDB::MariaDB(), dbname = "tradeflows")
swd_oak <- tbl(con, "raw_comext_monthly") %>%
    # Filter import flows and oak sawnwood
    filter(flowcode == 1 & productcode == "44079190") %>% 
    collect()
# Load reporter country codes and names
reporter_names <- tbl(con, 'vld_comext_reporter') %>% collect()
# Load partner codes and names
partner_names <- tbl(con, 'vld_comext_partner') %>%collect()
# Add reporter and partner information
swd_oak <- swd_oak %>%
    left_join(partner_names, by='partnercode') %>%
    left_join(reporter_names, by='reportercode')
RMariaDB::dbDisconnect(con)
# Now use this function 
# select the first partner for each reporter:
select_main_partners(swd_oak)
# Select the first 3 partners for each reporter:
select_main_partners(swd_oak, slice_n=1:3)

## End(Not run)

stix-global/eutradeflows documentation built on Nov. 13, 2020, 9:23 p.m.