Skip to content

Instantly share code, notes, and snippets.

View randrescastaneda's full-sized avatar
😊
I may be slow to respond.

R.Andrés Castañeda randrescastaneda

😊
I may be slow to respond.
View GitHub Profile
@randrescastaneda
randrescastaneda / examples_handbook_GMD.do
Created February 20, 2020 14:16
Replicate basic poverty and inequality measures using GMD data from the world Bank
/*==================================================
project: Examples of the handbook using GMD
Author: Andres Castaneda
Dependencies: The World Bank
----------------------------------------------------
Creation Date: 6 Jul 2018 - 12:03
Modification Date:
Do-file version: 01
References:
Output: http://eca/povdata/examples_handbook_GMD.DO
@randrescastaneda
randrescastaneda / maxN.R
Last active October 3, 2019 15:50
N highest of vector. This function was created by [Zach](https://stackoverflow.com/users/345660/zach) in this [post](https://stackoverflow.com/questions/2453326/fastest-way-to-find-second-third-highest-lowest-value-in-vector-or-column). I just keep it here for storage purposes.
maxN <- function(x, N=2, decreasing = FALSE){
len <- length(x)
if(N>len){
warning('N greater than length(x). Setting N=length(x)')
N <- length(x)
}
if (decreasing == FALSE) {
sort(x,partial=len-N+1)[len-N+1]
} else {
-sort(-x,partial=len-N+1)[len-N+1]
@randrescastaneda
randrescastaneda / dir_size.R
Created September 12, 2019 14:41
Calculate size of directories. Display directory tree and returns complete data frame
# requires data.table and data.tree
dir_size <- function(path = ".",
limit = 25,
sharet = .1) {
# get file from directory path
a <- list.files(path,
all.files = TRUE,
recursive = TRUE,
full.names = TRUE)
@randrescastaneda
randrescastaneda / bibtex_2academic.R
Last active July 6, 2019 11:51 — forked from lbusett/bibtex_2academic.R
script for importing publications from a "bibtex" file to a hugo-academic website
#' @title bibtex_2academic
#' @description import publications from a bibtex file to a hugo-academic website
#' @author Lorenzo Busetto, phD (2017) <lbusett@gmail.com>
#' @modified Peter Paul Pichler (2019) <pichler@pik-potsdam.de>
#' @modified R.Andres Castaneda (2019) <acastanedaa@worldbank.org>
bibtex_2academic <- function(bibfile,
outfold,
abstract = FALSE,
overwrite = FALSE) {