Skip to content

Instantly share code, notes, and snippets.

View franvillamil's full-sized avatar

Francisco Villamil franvillamil

View GitHub Profile
@franvillamil
franvillamil / figure.sublime-snippet
Created January 18, 2024 08:51
Sublime Text snippets
<snippet>
<content><![CDATA[
% ----------------------------------------------------
\\begin{figure*}[htb!]
\\centering
\\includegraphics[width = $1\\textwidth]{$2}
\\caption{$3}\\label{fig:$4}
\\end{figure*}
% ----------------------------------------------------
]]></content>
setwd("...")
library(RSelenium)
library(netstat)
library(rvest)
library(purrr)
## -------------------------------------------
## URL list
@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")
# Generated by Sync Settings for Atom
<https://github.com/atom-community/sync-settings>
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))
)
# 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
@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",
@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 / 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 / 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"),