Skip to content

Instantly share code, notes, and snippets.

@patperu
Created May 6, 2013 17:25
Show Gist options
  • Save patperu/5526588 to your computer and use it in GitHub Desktop.
Save patperu/5526588 to your computer and use it in GitHub Desktop.
library(data.table)
library(RODBC)
options(stringsAsFactors = FALSE)
setwd("E:/income")
channel <- odbcConnectAccess("italy_payment20130424.mdb")
payment <- sqlFetch(channel, "payment")
odbcClose(channel)
py <- data.table(payment)
py.y <- py[, list(Amount=sum(amountEuro), Payments=length(paymentId)), by=year]
py.y <- py.y[order(py.y$year), ]
pNum <- function(x) { prettyNum(x, big.mark = ",") }
py.y <- transform(py.y, Amount = pNum(Amount),
Payments = pNum(Payments))
save(payment, py.y, file="italy_payment20130424.rdata")
py.y
#>py.y
# year Amount Payments
# 1: 2002 225,044,996 34,863
# 2: 2003 518,129,556 93,393
# 3: 2004 877,440,031 174,380
# 4: 2005 1,098,903,909 202,623
# 5: 2006 1,151,378,132 176,257
# 6: 2007 4,116,956,843 516,839
# 7: 2008 5,781,514,892 1,226,217
# 8: 2009 5,845,769,751 1,417,461
# 9: 2010 545,373,509 191
# 10: 2011 2,556,812,788 52,728
# 11: 2012 2,908,377,605 55,105
# 12: NA 958,109,071 592,479
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment