Skip to content

Instantly share code, notes, and snippets.

@patperu
patperu / Konten.r
Created July 12, 2011 15:24
Verteilung von Konten
#
# Korrektur 13.07.2011
# - In 'fracbelow' = sort muss "decreasing = TRUE"
#
library(reshape) # für melt
library(ggplot2) # für plot
# Zufallsgenerator setzen
set.seed(123)
setwd("D:/a")
options(stringsAsFactors = FALSE)
TrimWhiteSpaces <- function(x) {
out <- sub("^[[:space:]]*(.*?)[[:space:]]*$", "\\1", x, perl=TRUE)
}
df <- read.csv("Authors.csv", skip = 1, nrows = 201)[, -1]
@patperu
patperu / Map_pwt.R
Created March 28, 2012 16:20
Choropleth map in R
#
# Map the 'Purchasing Power Parity (PPP)
# converted GDP per capita' from pwt7.0
# using a shapefile
#
library(maptools)
library(pwt)
library(classInt)
@patperu
patperu / reduce_ex.R
Created July 7, 2012 11:06
Reduce Function
# see ?Reduce
cfrac <- function(x) Reduce(function(u, v) (u / v) + 1, x)
cfrac(c(5, 7))
#[1] 1.714286
#ok
(5/7)+1
#[1] 1.714286
@patperu
patperu / Deprivation_Measure.R
Created July 25, 2012 08:13
Multiple Deprivation Measure
# Journal of the Statistical and Social Inquiry Society of Ireland
# Vol. XXXI
# DEVELOPING DEPRIVATION MEASURES FOR NORTHERN IRELAND*
# MICHAEL NOBLE, MYFANWY LLOYD GEMMA WRIGHT CHRIS DIBBEN GEORGE SMITH
# University of Oxford
# (read before the Society, 27 September 2001)
# page 21
# https://www.dropbox.com/sh/y5jk16lvgpojphf/gFB3Sqp49b
set.seed(345)
@patperu
patperu / Reduce_mapply.R
Created September 2, 2012 08:00
Reduce and mapply
x <- data.frame(id= 1:5, wz=LETTERS[1:5], matrix(1:40, ncol=8) )
x1 <- x[, c(1:2, 3:6)]
x2 <- x[, c(1:2, 7)]
x3 <- x[, c(1:2, 8:10)]
l <- list(x1, x2, x3)
l[[3]] <- l[[3]][order(l[[3]]$id, decreasing = TRUE),]
l
# pfff
@patperu
patperu / README.md
Last active December 15, 2015 11:49 — forked from mbostock/.block
d3-Calendar view of Traffic Injury Data from Berlin

This example demonstrates loading of CSV data, which is then quantized into a diverging color scale. The values are visualized as colored cells per day. Days are arranged into columns by week, then grouped by month and years. Colors by Cynthia Brewer. Layout inspired by Rick Wicklin and Robert Allison. Dow Jones historical data copyright Yahoo! Finance or independent data provider; fair use for educational purposes.

Edited to play with Traffic Injury Data from Berlin for the period 2008-01-01 - 2013-01-31 Source for the csv: Amt für Statistik Berlin Brandenburg

library(data.table)
library(RODBC)
options(stringsAsFactors = FALSE)
setwd("E:/income")
channel <- odbcConnectAccess("italy_payment20130424.mdb")
payment <- sqlFetch(channel, "payment")
odbcClose(channel)
@patperu
patperu / Emilia-Romagna.json
Created March 2, 2014 19:51
Emilia-Romagna.json // topojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@patperu
patperu / G62.R
Last active August 29, 2015 13:57
Plot "G62 -- Grado di diffusione di Internet nelle famiglie"
# see http://bit.ly/Nt5jpg
# http://www.datamediahub.it/2014/03/18/societa-dellinformazione-il-ritmo-di-crescita-delle-regioni-in-10-anni-mappa-interattiva/
library(ggplot2)
library(reshape2)
g62 <- read.csv2("g62.csv", skip = 1)
x <- g62[!colnames(g62) %in% paste0("X", 1995:2002)]