Using Gtfs Sydney Buses Data With Dplyr

General Transit Feed Specification (GTFS) data is freely available for Sydney Buses. I thought I would go through and see how easy it is to query and create something meaningful. Reading the files in was rather trivial and required the work of the very common eval(parse()) combination: tables <- c("trips", "stops", "stop_times", "routes") for(tbl in tables) { eval(parse(text=paste0(tbl, " <- read.csv(unz('./sydney_buses_gtfs_static.zip','", tbl, ".txt'), row.names=NULL)") )) } My first attempt made use of plyr library, but I ended up finding that slightly messy. [Read More]

Geocoding Using Osm

Using API calls is probably the easiest way to geocode address. Here is some sample R code which demonstrates how this can be done using two different sites: library(rjson) address = "321 kent st, sydney,nsw 2000, australia" format = "json" addressdetails = 0 # nominatim API has a "fair usage" policy but is more or less unlimited # you could in theory just install your own stack, and query that... url = paste0("http://nominatim. [Read More]

Recorded Crime Rates In Nsw From 1995 To 2009

Learn About Tableau I thought I would have a look at some open data and I came across the crime data set. The data used is: Recorded Crime Dataset (NSW) Postcode 2011 to Local Government Area 2011 Using R I thought this was a good opportunity to practise some R skills, though it could have easily been accomplished in Python as well. In order to read the data into R “nicely” I saved the relevant data into csv format. [Read More]

Create R Package As Fast As Possible

Apparently creating R packages is a good idea for code reuse. So what’s the best way to do it? Hopefully in this short blog post I will take you from start to finish as quickly as possible (omitting details for you to fill in) Useful Packages Firstly install devtools: install.packages("devtools", dependencies = TRUE) This is for using dev_mode() which will isolate an environment for you to do more testing. library(devtools) dev_mode() create() Navigate to the working directory and just create a package: [Read More]

Constructors In R And Python

The ability to construct your own abstractions is an important part of object orientated programming language. In this post we will quickly run through the differences between building constructors in R and Python. Declaring constructions Python In python to declare a constructor we use: class Person: def __init__(self, name): self.name = name In python methods can be added dynamically. e.g. from types import MethodType class Person: def __init__(self, name): self. [Read More]

Short Introduction To Ggplot2 In R

ggplot2 (grammar of graphics plot) is a twist on the traditional way of displaying graphics, and will differ slighly compared with the plot functions in R. Layers The general idea of GOG (grammar of graphics) is that graphics can be seperated into layers. From Wickham’s paper, the layers can be summarised as follows: data or aesthetic mappings, which describe the variables (e.g. x ~ y plot) geometric objects, which describe what you see, (e. [Read More]