Created
April 15, 2013 08:56
-
-
Save Su-Shee/5386828 to your computer and use it in GitHub Desktop.
R sqldf
This file contains 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
# now let's see if sqldf works nicely. :) | |
library(sqldf); | |
file <- '../data/cleaned-einwohnermelderegister-2011.csv' | |
csv <- read.csv(file, header = TRUE, sep = ';') | |
# rename columns like the postgres schema | |
colnames(csv) <- c("official_district", "district", "gender", "nationality", "age", "quantity") | |
# show the three largest districts by inhabitants | |
sqldf("SELECT district, sum(quantity) FROM csv GROUP BY district ORDER BY sum(quantity) DESC LIMIT 3") | |
# list by how many women per district | |
sqldf("SELECT district, sum(quantity) FROM csv WHERE gender = 'f' GROUP BY district ORDER BY sum(quantity) DESC LIMIT 3") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment