Skip to content

Instantly share code, notes, and snippets.

@jstray
Created September 18, 2012 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jstray/3741250 to your computer and use it in GitHub Desktop.
Save jstray/3741250 to your computer and use it in GitHub Desktop.
Load in the UK house of Lords data
library(proxy) # need custom distance function capability
# -------------------------------- Load data ------------------------------
# Load in vote history
# strip out vote description, date, etc, and transpose so each row is an MP
votetable = read.csv("votematrix-lords.csv", header=T, sep=",")
votes = votetable[, 5:1047]
votes = t(votes)
# Load Lord descriptions, and order by MPID, which is the column ordering in votes
lords = read.csv("lords.csv", header=T, sep=",")
lords = lords[order(lords[,"mpid"]),]
# Turn "aye" (encoded as 2) into +1, and "nay" (encoded as 4) into -1, all else zero
ayes <- votes == 2
nays <- votes == 4
votes <- array(0, dim(votes))
votes[ayes] <- 1
votes[nays] <- -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment