View sparkbar.R
# Takes an ordered vector of numeric values and returns a small bar chart made | |
# out of Unicode block elements. Works well inside dplyr mutate() or summarise() | |
# calls on grouped data frames. | |
sparkbar <- function(values) { | |
span <- max(values) - min(values) | |
if(span > 0 & !is.na(span)) { | |
steps <- round(values / (span / 7)) | |
blocks <- c('▁', '▂', '▃', '▄', '▅', '▆', '▇', '█') | |
paste(sapply(steps - (min(steps) - 1), function(i) blocks[i]), collapse = '') |
View gist:7770536
/* | |
Copyright 2013 Martin Hawksey | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software |
View add_numbers.py
import csv | |
import json | |
INPUTFILE = "History_Journal_Articles_KW.csv" | |
OUTPUTFILE = INPUTFILE[:-4] + "_numbered.csv" | |
in_file = open(INPUTFILE, "r") # "r" == Open file for reading | |
out_file = open(OUTPUTFILE, "w") # "w" for writing |