Skip to content

Instantly share code, notes, and snippets.

View franvillamil's full-sized avatar

Francisco Villamil franvillamil

View GitHub Profile
setwd("...")
library(ggplot2)
## DATA: Ron Francisco's European Protest and Coercion Data.
## Downloaded (.xls files) from http://web.ku.edu/~ronfrand/data/ and converted into .csv with MS Excel.
# Defining main dataframe and specifying country codes
data = data.frame(date = c(), action = c(), freq = c(), country = c())
countrycodes = c("Albania80-88", "Albania89-95", "Austria80-95", "Belgium80-87", "Belgium88-95",
@franvillamil
franvillamil / methods-hw1.R
Last active August 29, 2015 14:19
Methods II - Homework I code
# ============================== #
# MACIS - Methods II #
# Homework 1 - May 1, 2015 #
# ------------------ #
# Francisco Villamil #
# ============================== #
setwd("...")
lapply(c("rms", "lme4", "ggplot2", "foreign", "aod"),
@franvillamil
franvillamil / methods-hw2.R
Last active August 29, 2015 14:21
Methods II - Homework 2 code
# ===================================== #
# MACIS - Methods II #
# Homework 2 - May 15, 2015 #
# -------- #
# Francisco Villamil #
# ===================================== #
setwd("~/Dropbox/MACIS/Methods\ II/hw2")
lapply(c("foreign", "ggplot2", "MASS", "VGAM", "boot"),
@franvillamil
franvillamil / scrapping_INE_census.R
Last active September 26, 2017 15:28
R code to scrap the INE website and get census data
setwd("~")
library(rvest)
library(stringr)
# ---------------
# FUNCTIONS
prov_code_to_name = function(x){
p = c("alava", "albacete", "alicante", "almeria", "avila",
"badajoz", "baleares", "barcelona", "burgos", "caceres",
@franvillamil
franvillamil / scrap_trip_advisor.R
Created February 15, 2019 13:15
R code to scrap reviews information from TripAdvisor for a number of Spanish cities
rm(list = ls())
setwd("~/Documents/Academic/courses/SocDataScience_feb19/project")
library(rvest)
library(stringr)
library(dplyr)
options(stringsAsFactors = FALSE)
url_list = c("https://www.tripadvisor.com/Restaurants-g187514-Madrid.html",
"https://www.tripadvisor.com/Restaurants-g187497-Barcelona_Catalonia.html",
"https://www.tripadvisor.com/Restaurants-g187454-Bilbao_Province_of_Vizcaya_Basque_Country.html",
# R Script
setwd("~/Downloads") # NOTE you might want to change this!
# NOTE: It is usually best to transform Excel files into .csv files (in Save as > Csv file)
# but anyway, I'm using here the readxl package.
# Packages
library(vegan) # Species diversity
library(ggplot2)
# ------------------------------
gen_dat = function(baseline, change, sd) {
data.frame(
y = c(rnorm(n=320, mean=baseline, sd=sd),
rnorm(n=90, mean=baseline+change, sd=sd)),
x = c(rep("out", 320), rep("in", 90))
)
# Generated by Sync Settings for Atom
<https://github.com/atom-community/sync-settings>
@franvillamil
franvillamil / INE_apellidos.R
Last active April 28, 2021 11:54
Scrap apellidos from INE & aggregate
setwd("...")
library(stringr)
library(RSelenium)
library(XML)
library(dplyr)
library(muniSpain)
options(stringsAsFactors = FALSE)
# Encoding problems, using Spanish enconding here
Sys.setlocale("LC_ALL", "ES_ES.UTF-8")
setwd("...")
library(RSelenium)
library(netstat)
library(rvest)
library(purrr)
## -------------------------------------------
## URL list