Skip to content

Instantly share code, notes, and snippets.

View martinctc's full-sized avatar
🔥
Packaging up my workflows

Martin Chan martinctc

🔥
Packaging up my workflows
View GitHub Profile
library(ggplot2)
library(dplyr)
electrial_consumption <- tibble::tribble(
~country, ~pct,
"Italy", -27,
"Spain", -21,
"Belgium", -17,
"Austria", -16,
"France", -16,
@martinctc
martinctc / HyperlinkWorksheetNames.vbs
Created November 29, 2017 13:35
[Hyperlink Worksheet Names] Create an "Index" worksheet with hyperlinks to each worksheet in #Excel.
Sub HyperlinkWorksheetNames()
'Code by Deep Dave, makes a Table of Content on a new sheet named Index
'Check out some helpful Excel blogs on www.NeedForExcel.com
Dim R() As Variant, WS As Worksheet, i As Byte, Counter As Integer, LR As Integer
On Error Resume Next 'If the Worksheet named Index does not exist, this will ignore the generated error
Application.DisplayAlerts = False 'Display alerts when set to false, will not ask confirmation
@martinctc
martinctc / surveyr.R
Last active March 5, 2019 15:13
[surveyr] Useful functions for tidy survey analysis. Under development... #R
#### Source this from github using following link ####
# devtools::source_gist("https://gist.github.com/martinctc/53444d4847055a870417f5b279f1b8bd", filename="surveyr.R")
#' Calculate weight table using a single source/target column
#' (indicating what proportions need to be multiplied to achieve weighted proportions)
#'
#' @param x Data frame containing columns to be weighted
#' @param target bare (unquoted) column name of the variable used for creating weight
#' @param weights vector containing the proportions of what each value of the target column should take
library(tidyverse)
library(ggalt) # devtools::install_github("hrbrmstr/ggalt")
df <- data_frame(
benchmark=c(0.52, 0.57, 0.60, 0.63, 0.64, 0.67),
referrals=c(4.2, 4.5, 4, 4.5, 3.9, 3.6),
year=c(2011, 2012, 2013, 2014, 2015, 2016)
)
# as of 2016-11-07 ggplot2 geom_label() seems to be ignoring the "angle" parameter, hence the non-ideal use of geom_text()
@jadianes
jadianes / server.R
Created August 13, 2015 11:23
Sentiment Analyser Shiny app
library(shiny)
library(tm)
library(SnowballC)
library(randomForest)
options(mc.cores=1)
build_model <- function(new_data_df, sparsity) {
# Create new data corpus
new_corpus <- Corpus(VectorSource(new_data_df$Text))
@StephenOTT
StephenOTT / gist:4260308
Created December 11, 2012 17:01
Find and Replace values in column with array values - Excel
Sub Macro1()
findArray = Array("/01/", "/02/", "/03/", "/04/", "/05/", "/06/", "/07/", "/08/", "/09/", "/10/", "/11/", "/12/")
replArray = Array("/Jan/", "/Feb/", "/Mar/", "/Apr/", "/May/", "/Jun/", "/Jul/", "/Aug/", "/Sep/", "/Oct/", "/Nov/", "/Dec/")
For i = 0 To UBound(findArray)
Selection.EntireColumn.Select
Selection.Replace What:=findArray(i), Replacement:=replArray(i), LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False