Skip to content

Instantly share code, notes, and snippets.

@peterhurford
Last active February 3, 2019 03:12
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 peterhurford/d79374f964058900f4757e047da30365 to your computer and use it in GitHub Desktop.
Save peterhurford/d79374f964058900f4757e047da30365 to your computer and use it in GitHub Desktop.
Look at Mint transaction data via R
## Load libraries
if (!require(readr)) { install.packages("readr") }; library(readr)
if (!require(magrittr)) { install.packages("magrittr") }; library(magrittr)
if (!require(dplyr)) { install.packages("dplyr") }; library(dplyr)
if (!require(tibbletime)) { install.packages("tibbletime") }; library(tibbletime)
if (!require(lubridate)) { install.packages("lubridate") }; library(lubridate)
if (!require(devtools)) { install.packages("devtools") }; library(devtools)
if (!require(shinyview)) { install_github("peterhurford/shinyview") }; library(shinyview)
## Load Mint transactions
trans <- read_csv("~/Downloads/transactions.csv")
## Parse it into dataframe
trans <- trans %>%
mutate(Date = as.Date(Date, "%m/%d/%Y")) %>%
arrange(Date) %>%
as_tbl_time(index = Date) %>%
filter_time("2018-01" ~ "2018-03") %>% # Change this the appropriate date range
mutate(moy = month(Date))
## Look at amount by category by month
view_trans_by_month <- function(trans) {
trans %>%
filter(`Transaction Type` == "debit") %>%
select(Date, moy, Amount, Description, Category) %>%
distinct %>%
group_by(moy, Category) %>%
summarise(total = sum(Amount)) %>%
arrange(-moy) %>%
shiny_view
}
## Look at individual transactions
view_trans <- function(trans) {
trans %>%
filter(`Transaction Type` == "debit") %>%
select(Date, moy, Amount, Description, Category) %>%
distinct %>%
arrange(moy, Category) %>%
shiny_view
}
view_trans_by_month(trans)
view_trans(trans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment