Skip to content

Instantly share code, notes, and snippets.

@rpietro
rpietro / random_subset.r
Created September 9, 2013 14:41
script to extract a random sample out of a dataset
# making the random sample reproducible, makes it easier to take other samples
set.seed(123)
# add your local path below
setwd("")
fulldat <- read.csv("fulldat.csv", header = TRUE)
#removing duplicates
fulldat <- fulldat[!duplicated(fulldat$var),]
str(fulldat)
@rpietro
rpietro / citchunk.r
Created September 15, 2013 13:00
citation chunk that goes along the reports package
<snippet>
<content><![CDATA[
```{r setup, include = FALSE}
library(reports); library(slidify); library(knitcitations); library(knitr)
opts_chunk$set(cache = FALSE)
BIB <- system.file("extdata/docs/example.bib", package = "reports")
bib <- read.bibtex(BIB)
```
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
@rpietro
rpietro / ed_obs.r
Created September 17, 2013 04:35
education vs employment for OECD data
# setting working directory
setwd("~/Desktop")
# calling packages, need to install packages with install.packages if you haven't installed them before
library(ggplot2)
library(lubridate)
#------------------------------------------------------------------------------
# importing data
@rpietro
rpietro / ex.n3
Created September 20, 2013 00:20
N3 file that goes with http://goo.gl/OwjblF
@prefix rdfs: <http://www.w3.org/rdf/schema/#> .
@prefix ex: <http://example.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:Methane
rdfs:label "methane"^^xsd:string ;
ex:formula "CH4"^^xsd:string ;
ex:carbonCount "1"^^xsd:integer .
ex:Ethane
rdfs:label "ethane"^^xsd:string ;
# script below from http://goo.gl/OwjblF
# install.packages("rrdf")
require(rrdf)
#------------------------------------------------------------------------------
# creating store
ontStore = new.rdf()
@rpietro
rpietro / wdi_hack.r
Created September 20, 2013 01:58
WDI package - script from http://goo.gl/DSb9XY
# code from http://goo.gl/DSb9XY
install.packages("WDI")
library(ggplot2)
library(WDI)
DF <- WDI(country=c("US","CA","MX"), indicator="NY.GDP.MKTP.KD.ZG", start=1990, end=2008)
ggplot(DF, aes(year, NY.GDP.MKTP.KD.ZG, color=country))+geom_line(stat="identity")+theme_bw()+xlab("Year")+opts(title="Annual GDP Growth rate (%)")+ylab("")
# Tab completion
a<Tab> # first car and hit tab
# Instropection
a = 'Foo says hello'
a? # shows info about variable, docstrings if it is function/instance method
aa?? # shows source code
# Unix Commands
!git # normal git command inside Ipython. Most of the Unix commands can be used this way
@rpietro
rpietro / ed.csv
Created September 23, 2013 01:52
Primary education (ISCED 1) Percentage of Repeaters- All Countries - data scraped from http://goo.gl/eQjo2j
Country Level Units As Of ~5Y Ago ~10Y Ago ~25Y Ago
Afghanistan 16.26% percent 2005 9.62%
Laos 12.46% percent 2011 16.95% 20.00%
Latvia 2.13% percent 2010 2.85% 1.97%
Lebanon 9.22% percent 2011 9.16%
Lesotho 20.01% percent 2010 20.95% 19.62% 23.68%
Kyrgyzstan 0.07% percent 2011 0.08% 0.16%
Libya 9.58% percent 1983 14.73%
Lithuania 0.53% percent 2010 0.62% 0.66%
Luxembourg 0.00% percent 2010 4.40% 6.14%
@rpietro
rpietro / quandl.r
Created September 23, 2013 01:59
playing with educational data on Quandl
Quandl.auth("") # add your token, which you have to get at http://www.quandl.com/users/edit
library(devtools)
install_github('R-package','quandl')
require(Quandl)
require(ggplot2)
require(RCurl)
data <- getURL("https://gist.github.com/rpietro/6665635/raw/edb700cc7b2110c3f7dd4d559221f351e17369fd/ed.csv")
ed <- read.csv(data)
head(ed)
@rpietro
rpietro / ed_wb.txt
Last active December 23, 2015 17:00
list of education-related variables from World Bank based on World Bank Linked Data at http://goo.gl/2TYzYp
Literacy rate, youth total (% of people ages 15-24)
School enrolment, preprimary, national source (% gross)
Gross intake ratio in grade 1, total, national source (% of relevant age group)
Gender parity index for gross intake ratio in grade 1
Rate of out of school children, national source (% of relevant age group)
Primary completion rate, total, national source (% of relevant age group)
Gender parity index for primary completion rate
Progression to secondary school, national source (%)
Lower secondary completion rate, total, national source (% of relevant age group)
Lower secondary education, classrooms, national source