Thursday, October 16, 2014

Pro I594 Contributions

Post on pro I594 Contributions is here. Code below.

setwd("C:/Politics")
ALL <- read.csv("I594_WAAGR.csv", header = TRUE, strip.white = TRUE, quote = "", na.strings = "NA",stringsAsFactors = FALSE)
#exploratory code for data
require(plyr)

ByDonation <-
ddply(ALL, .(Amount),plyr::summarize,
SUM = sum(Amount),
CONTRIB = length(Contributor),
CONTRIB.UNIQ = length(unique(Contributor)),
STATE.UNIQ = length(unique(State))
)

ByContributor <-
ddply(ALL, .(Contributor),plyr::summarize,
SUM = sum(Amount),
CONTRIB = length(Contributor),
CONTRIB.UNIQ = length(unique(Contributor)),
STATE.UNIQ = length(unique(State))
)

ByState <-
ddply(ALL, .(State),plyr::summarize,
SUM = sum(Amount),
CONTRIB = length(Contributor),
CONTRIB.UNIQ = length(unique(Contributor)),
CITY.UNIQ = length(unique(City)),
ZIP.UNIQ = length(unique(Zip))
)

ByCity <-
ddply(ALL, .(City),plyr::summarize,
SUM = sum(Amount),
CONTRIB = length(Contributor),
CONTRIB.UNIQ = length(unique(Contributor)),
STATE.UNIQ = length(unique(State)),
ZIP.UNIQ = length(unique(Zip))
)

#arrange(ByState, desc(SUM))
#arrange(ByCity, desc(SUM))
#arrange(ByDonation, desc(SUM))
#arrange(ByContributor, desc(SUM))

sum(ALL$Amount)
quantile(as.integer(ALL$Amount), probs = seq(0, 1, 0.10), na.rm = TRUE)
arrange(ByDonation,desc(Amount))[1:10,]
arrange(ByContributor,desc(Amount))[1:10,]
arrange(ByState,desc(SUM))[1:10,]
arrange(ByCity,desc(SUM))[1:10,]

No comments:

Post a Comment