This file contains hidden or 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
| #--- | |
| #layout: post | |
| #title: "Venezuelan Parliamentary Election: What do the Polls Say?" | |
| #date: 2015-12-06 | |
| #category: [R] | |
| #tags: [Venezuela, election, polls] | |
| # comments: true | |
| #image: | |
| #--- |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
| height_ratio <- c(0.924324324, 1.081871345, 1, 0.971098266, 1.029761905, | |
| 0.935135135, 0.994252874, 0.908163265, 1.045714286, 1.18404908, | |
| 1.115606936, 0.971910112, 0.97752809, 0.978609626, 1, | |
| 0.933333333, 1.071428571, 0.944444444, 0.944444444, 1.017142857, | |
| 1.011111111, 1.011235955, 1.011235955, 1.089285714, 0.988888889, | |
| 1.011111111, 1.032967033, 1.044444444, 1, 1.086705202, | |
| 1.011560694, 1.005617978, 1.005617978, 1.005494505, 1.072222222, | |
| 1.011111111, 0.983783784, 0.967213115, 1.04519774, 1.027777778, | |
| 1.086705202, 1, 1.005347594, 0.983783784, 0.943005181, 1.057142857) |
This file contains hidden or 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
| require(magrittr) | |
| require(SciencesPo) | |
| # Latest polls: | |
| polls = NULL | |
| polls <- data.frame( rbind( | |
| Kapa = c(47.2,33,1000), | |
| ProRata = c(37,46,1200), | |
| U.Macedonia = c(42.5,43,1042), | |
| Public.Issue=c(45.5,45,1053), | |
| GPO=c(44.1,43.7,2453), |
This file contains hidden or 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
| # Tutorial and data based on the network visualization workshop published over https://rpubs.com/kateto/netviz | |
| #packages: | |
| library(igraph) | |
| library(RCurl) | |
| # get the data | |
| nodes <- read.csv("https://raw.githubusercontent.com/danielmarcelino/Datasets/master/Media-NODES.csv", header=T, as.is=T) | |
| ties <- read.csv("https://raw.githubusercontent.com/danielmarcelino/Datasets/master/Media-EDGES.csv", header=T, as.is=T) | |
| # Explore data: |
This file contains hidden or 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(ggplot2) | |
| #install.packages("lme4") | |
| library(lme4) | |
| library(doBy) | |
| library(mice) | |
| ############### ############### | |
| # MI adjustments for final estimates | |
| ############### ############### | |
| finalMI <- function(var,beta,m){ |
This file contains hidden or 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
| # written by http://hannes.muehleisen.org/ | |
| # from http://stackoverflow.com/questions/16474696/read-system-tmp-dir-in-r | |
| gettmpdir <- | |
| function() { | |
| tm <- Sys.getenv(c('TMPDIR', 'TMP', 'TEMP')) | |
| d <- which(file.info(tm)$isdir & file.access(tm, 2) == 0) | |
| if (length(d) > 0) | |
| tm[[d[1]]] | |
| else if (.Platform$OS.type == 'windows') |
This file contains hidden or 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
| ################################################################################## | |
| ####################### SQLite Speed ##################################### | |
| ################################################################################## | |
| install.packages("sqldf") | |
| require(sqldf) | |
| #DataPath<-"C:/Data/NewTables/" | |
| #Datatbl<-list.files(DataPath) | |
| #Cwd<-getwd() | |
| #setwd(DataPath) | |
| #dat = lapply(Datatbl,read.csv, header = TRUE) |
This file contains hidden or 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(rvest) | |
| 'http://espn.go.com/sportsnation/teamrankings#table' %>>% | |
| html %>>% | |
| html_table() %>>% data.frame %>>% tbl_df -> data | |
| names(data) %<>% tolower() | |
| c('rank','team') -> names(data)[1:2] | |
| data$rank %>>% (gsub('\\.','',.)) %>>% as.numeric -> data$rank | |
| data[!is.na(data$rank),] -> data |
This file contains hidden or 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
| require(dplyr) | |
| require(RCurl) | |
| require(reshape2) | |
| require(rvest) | |
| require(pipeR) | |
| getGoogleResults <- function (search.term, show = 10){ | |
| Trim <- function (x) gsub("^\\s+|\\s+$", "", x) | |
| packages = c('rvest','dplyr','pipeR','reshape2') |