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
// ----------------------------------------------------------------------------- | |
// DEPENDENCIES | |
// ----------------------------------------------------------------------------- | |
// minimum version for `import spss` | |
version 16 | |
// version used for estimation | |
version 17 |
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
/* rs-theme-name: Dark UI Base16 Tomorrow Night */ | |
/* rs-theme-is-dark: TRUE */ | |
/* Dark UI from Randy3k's Wombat (https://github.com/randy3k/dotfiles/blob/master/.R/rstudio/themes/Wombat.rstheme) */ | |
/* "Tomorrow night" color scheme adapted from chriskempson's Base16 (https://github.com/chriskempson/base16). */ | |
.body { | |
background: #ffffff; | |
} |
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
# triangle.py | |
import math | |
def triangle_perimeter(a, b, c): | |
return a + b + c | |
def triangle_area(a, b, c): | |
p = triangle_perimeter(a, b, c) / 2 | |
x = math.sqrt(p * (p - a) * (p - b) * (p - c)) | |
return round(x, 2) |
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
# package dependency | |
library(haven) | |
path_in = "new_EB with more var_2004-2016.dta" | |
out_tsv = "new_EB.tsv" | |
out_sav = "new_EB.sav" | |
# name repair shows the issue with _merge | |
x = haven::read_dta(p, .name_repair = "universal") | |
names(x)[ names(x) == "._merge" ] = "MERGEVAR" |
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
# change of PRNG in R >= 3.6.0 | |
# use former PRNG | |
RNGkind(sample.kind = "Rounding") | |
# use new/fixed PRNG | |
RNGkind(sample.kind = "default") | |
# see ?Random for details |
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
library(cartography) | |
library(sp) | |
# Load data | |
data(nuts2006) | |
# Get a SpatialLinesDataFrame of countries borders | |
nuts0.contig.spdf <- getBorders(nuts0.spdf) | |
# Get the GDP per capita | |
nuts0.df$gdpcap <- nuts0.df$gdppps2008/nuts0.df$pop2008*1000000 |
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
## | |
## download all `ergm` sources from v3.0-1 to today | |
## | |
library(rvest) | |
d <- "ergm-sources" | |
dir.create(d, showWarnings = FALSE) | |
# current source |
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
R to python useful data wrangling snippets | |
The dplyr package in R makes data wrangling significantly easier. | |
The beauty of dplyr is that, by design, the options available are limited. | |
Specifically, a set of key verbs form the core of the package. | |
Using these verbs you can solve a wide range of data problems effectively in a shorter timeframe. | |
Whilse transitioning to Python I have greatly missed the ease with which I can think through and solve problems using dplyr in R. | |
The purpose of this document is to demonstrate how to execute the key dplyr verbs when manipulating data using Python (with the pandas package). | |
dplyr is organised around six key verbs |
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
library(tidyverse) | |
library(patchwork) | |
plot_pair <- function(data, x, y) { | |
ggplot(data, aes_string(x = x, y = y, color = "Species", shape = "Species")) + | |
geom_point() + | |
scale_color_brewer(palette = "Dark2") + | |
theme(legend.position = "none", plot.title = element_text(size = 7)) + | |
labs(x = NULL, y = NULL, title = paste0(y, " ~ ", x)) |
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
clear | |
input str500 x | |
"-73.974651 40.73868,-73.973391 40.73897,-73.97323 40.73955,-73.97298 40.7415304,-73.97247 40.7423406,-73.97229 40.7428504,-73.97213 40.74338,-73.971871 40.7440804,-73.97141 40.7446706,-73.97103 40.7455605,-73.970301 40.7465204,-73.96929 40.7472" | |
"-73.970301 40.7465204,-73.96929 40.7472" | |
end | |
// keep only the first pair of coordinates | |
replace x = regexr(x, ",.*", "") | |
// split by space, converting to numeric |
NewerOlder