Skip to content

Instantly share code, notes, and snippets.

View DataStrategist's full-sized avatar

Amit Kohli DataStrategist

View GitHub Profile
library(plyr)
library(ggplot2)
s <- read.csv("<filename.csv>", sep=",", row.names=NULL)
colnames(s) <- c("date", "type", "desc", "value", "balance", "acc")
s$date <- as.Date(s$date, format="%d/%m/%Y")
s <- s[,1:5]
s$month <- as.Date(cut(s$date, breaks="month"))
s <- subset(s, s$value < 0)
@DataStrategist
DataStrategist / easyModeNodeEdge.R
Last active July 17, 2016 15:45
This function takes inputs and converts them from a data.frame like FROM TO VALUE into two dataframes: Nodes and Edges. This is suitable for the packages VisNetwork and network3d.
## This function takes inputs and converts them from a data.frame like FROM TO VALUE into two dataframes:
## Nodes and Edges. This is suitable for the packages VisNetwork and network3d.
## output will be a list containing both dataframes
## The indexing is important. By default, the edges will be 1-indexed (for VisNetwork), but if you're using it with
## network3d, change the indexing to 0
easyMode <- function(df,Index=1){
nodes <- data.frame(name=df[,1:2] %>% unlist %>% as.character() %>% unique())
@DataStrategist
DataStrategist / Animated KPI Dashboard
Created February 2, 2016 20:39
A demonstration on how to make a KPI Dashboard that displays animated gifs depending on results.
library(googleVis)
## Set wd
setwd("your folder")
df <- data.frame(thing=c("A","B","C","D"),
measure=c(12,3,4.5,17))
## unimpresive dashboard
plot(gvisTable(df))
' Excel macro to export all VBA source code in this project to text files for proper source control versioning
' Requires enabling the Excel setting in Options/Trust Center/Trust Center Settings/Macro Settings/Trust access to the VBA project object model
' modified to ask what workbook to export stuff from instead of doing it automatically for Activeworkbook.
Public Sub ExportVisualBasicCode()
Const Module = 1
Const ClassModule = 2
Const Form = 3
Const Document = 100
Const Padding = 24
SankeyR <- function(inputs, losses, unit, labels, format="plot",
showPercent=TRUE, maxScale=2.5, minFont=0.5,
titt=""){
########################
# SankeyR version 1.02 (updated June 3, 2015)
# is a function for creating Sankey Diagrams in R.
# See http://www.sankey-diagrams.com for excellent examples of Sankey Diagrams.
#
# OPTIONS:
# 'inputs' is a vector of input values