Skip to content

Instantly share code, notes, and snippets.

@agstudy
Created April 13, 2013 08:40
Show Gist options
  • Save agstudy/5377621 to your computer and use it in GitHub Desktop.
Save agstudy/5377621 to your computer and use it in GitHub Desktop.
## read data
ll <- readLines(textConnection('28/03/13 FACTURE CARTE DU 240313 PHOTOBOX SARTROUVILLE CARTE -30
25/03/13 2EME TIERS SUR FACTURE DE 180 EUR DU 240113 CAROLL INTL PARI -60
25/03/13 RETRAIT DAB 24/03/13 11H15 166936 BNP PARIBAS PARIS -200.50
18/03/13 PRELEVEMENT TRESOR PUBLIC 94 IMPOT NUM 005002 ECH 18 -500'))
## convert data to a data.frame
dat <- do.call(rbind,strsplit(gsub('[ ]{2,}','|',ll),'\\|'))
## name columns
colnames(dat) <- c('date','category','desc','amount')
dat <- as.data.frame(dat)
## type variables
dat$date <- as.Date(dat$date,'%d/%m/%y')
dat$amount <- as.numeric(as.character(dat$amount))
dat$desc <- as.character(dat$desc)
## you can aggegate per date for example
library(plyr)
dat.daily <- ddply(dat,.(date),summarise,amount = sum(amount))
library(ggplot2)
ggplot(dat.daily)+
geom_line(aes(x=date,y=amount))
## you can compute amout per category
table(dat$amount,dat$category)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment