Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mauricio Vargas
committed
Feb 20, 2018
0 parents
commit e5daec1
Showing
9 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Package: economiccomplexity | ||
Type: Package | ||
Title: What the Package Does (Title Case) | ||
Version: 0.1.0 | ||
Author: Who wrote it | ||
Maintainer: The package maintainer <yourself@somewhere.net> | ||
Description: More about what it does (maybe more than one line) | ||
Use four spaces when indenting paragraphs within the Description. | ||
License: MIT + file LICENSE | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Imports: | ||
magrittr, | ||
dplyr, | ||
tidyr, | ||
stats | ||
RoxygenNote: 6.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(rca) | ||
importFrom(dplyr,distinct) | ||
importFrom(dplyr,filter) | ||
importFrom(dplyr,group_by) | ||
importFrom(dplyr,mutate) | ||
importFrom(dplyr,select) | ||
importFrom(dplyr,select_) | ||
importFrom(dplyr,ungroup) | ||
importFrom(magrittr,"%>%") | ||
importFrom(stats,setNames) | ||
importFrom(tidyr,unite) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
globalVariables( | ||
c( | ||
"pairs", | ||
"select", | ||
"sum_c_p_xcp", | ||
"sum_c_xcp", | ||
"sum_p_xcp", | ||
"xcp" | ||
) | ||
) | ||
|
||
#' Computes RCA (Revealed Comparative Advantage) | ||
#' | ||
#' @export | ||
#' @param data a tibble (or data frame) in long format | ||
#' @param c name of column that contains countries (by default is "country") | ||
#' @param p name of column that contains products (by default is "product") | ||
#' @param value name of column that contains trade values (by default is "export_val") | ||
#' @importFrom magrittr %>% | ||
#' @importFrom dplyr select_ select mutate group_by ungroup filter distinct | ||
#' @importFrom tidyr unite | ||
#' @importFrom stats setNames | ||
#' @examples | ||
#' # Demo dataset 'Fantasy World' | ||
#' rca(fantasy_world_long) | ||
#' @keywords functions | ||
|
||
rca <- function(data = data, c = "country", p = "product", value = "export_val") { | ||
data_rca <- data %>% | ||
select_(.dots = c(c, p, value)) %>% | ||
setNames(c("c", "p", "value")) %>% | ||
unite(pairs, c, p, remove = FALSE) %>% | ||
group_by(p) %>% # Sum by categories in P | ||
mutate(sum_p_xcp = sum(value, na.rm = TRUE)) %>% | ||
ungroup() %>% | ||
group_by(c) %>% # Sum by categories in C | ||
mutate(sum_c_xcp = sum(value, na.rm = TRUE)) %>% | ||
ungroup() %>% | ||
group_by(pairs) %>% # Sum by pairs (C,P) | ||
mutate(xcp = sum(value, na.rm = TRUE)) %>% | ||
ungroup() %>% | ||
distinct(pairs, .keep_all = TRUE) %>% | ||
select(-pairs) %>% | ||
filter(sum_c_xcp > 0) %>% | ||
mutate(sum_c_p_xcp = sum(xcp, na.rm = TRUE)) %>% # Total sum | ||
mutate(rca = (xcp / sum_c_xcp) / (sum_p_xcp / sum_c_p_xcp)) %>% # Compute RCA | ||
select(c, p, value, rca) | ||
return(data_rca) | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: Default | ||
SaveWorkspace: Default | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: Sweave | ||
LaTeX: pdfLaTeX | ||
|
||
AutoAppendNewline: Yes | ||
StripTrailingWhitespace: Yes | ||
|
||
BuildType: Package | ||
PackageUseDevtools: Yes | ||
PackageInstallArgs: --no-multiarch --with-keep.source | ||
PackageRoxygenize: rd,collate,namespace,vignette |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.