Skip to content

Instantly share code, notes, and snippets.

View raffdoc's full-sized avatar

Rafik Margaryan raffdoc

View GitHub Profile
@psychemedia
psychemedia / README.md
Last active June 12, 2021 18:45
Example shiny app for loading in CSV file containing two location columns and an amount column and plotting great circle lines between each pair or points with line thickness related to amount. About: http://blog.ouseful.info/2014/03/24/experimenting-with-r-point-to-point-mapping-with-great-circles/
@ramnathv
ramnathv / Makefile
Last active January 16, 2021 13:47
R Markdown to IPython Notebook
example.md: example.Rmd
./knit
example.ipynb: example.md
notedown example.md | sed 's/%%r/%%R/' > example.ipynb
@jbryer
jbryer / package.R
Last active January 16, 2022 06:31
#' Simplified loading and installing of packages
#'
#' This is a wrapper to \code{\link{require}} and \code{\link{install.packages}}.
#' Specifically, this will first try to load the package(s) and if not found
#' it will install then load the packages. Additionally, if the
#' \code{update=TRUE} parameter is specified it will check the currently
#' installed package version with what is available on CRAN (or mirror) and
#' install the newer version.
#'
#' @param pkgs a character vector with the names of the packages to load.
@tadast
tadast / countries_codes_and_coordinates.csv
Last active April 20, 2025 01:32
Countries with their (ISO 3166-1) Alpha-2 code, Alpha-3 code, UN M49, average latitude and longitude coordinates
Country Alpha-2 code Alpha-3 code Numeric code Latitude (average) Longitude (average)
Afghanistan AF AFG 4 33 65
Åland Islands AX ALA 248 60.116667 19.9
Albania AL ALB 8 41 20
Algeria DZ DZA 12 28 3
American Samoa AS ASM 16 -14.3333 -170
Andorra AD AND 20 42.5 1.6
Angola AO AGO 24 -12.5 18.5
Anguilla AI AIA 660 18.25 -63.1667
Antarctica AQ ATA 10 -90 0
set.seed(12345)
dat <- data.frame(category=rep(c("Food", "Drinks"),20),
product=rep(c("Cheese", "Wine", "Bread", "Beer"), 10),
year=sort(rep(c(2004:2013),4)),
value=sort(rnorm(40)))
dat <- dat[with(dat, order(category, year)),]
library(lattice)
# Change some of the default lattice settings
@ramnathv
ramnathv / README.md
Created January 30, 2014 00:33
Creating PDF Version of Slidify Presentations

This gist consists of a makefile and a script that can automate the creation of PDFs from Slidify generated HTML slides. The script assumes that the makefile and the script makepdf.js are in the same directory as the Rmd file. The makepdf.js script uses casperjs, a very useful utility to automate tasks that require browser interaction. You may follow the installation instructions on the casperjs website, to make sure that you have all the dependencies correctly installed before trying this out.

require(quantmod)
prepare.indicator = function(close, indicator, roc.n, normalize=FALSE, func=mean) {
rets = ROC(close, type="discrete", n=roc.n)
if(normalize) {
# Normalize the returns to daily
rets = ((1 + rets) ^ (1/roc.n)) - 1
}
@dlmace
dlmace / server.R
Last active December 29, 2015 07:29
require(shiny);
require(caret);
require(e1071);
require(randomForest);
require(nnet);
require(glmnet);
#code for plotting nnets, taken from: http://beckmw.wordpress.com/2013/03/04/visualizing-neural-networks-from-the-nnet-package/
# the formula of the output of train is off and doesn't work correctly though.
#Function for plotting nnets, not working right now

This is a short demo of how to use brew and knitr in combination with each other to get the best of the templating facilities in brew and the literate programming functions in knitr. The main idea is to write a function brew_knit

# Preprocess template using brew and then run knit on the output
brew_knit <- function(template, params, ...){
 brew::brew(template, envir = list2env(params))
 input = gsub(".Rnwe", '.Rnw', template)
 knitr::knit(input)
}
library(ggplot)
nosql.df <- read.csv("nosql.csv", header=TRUE)
nosql.df$Database <- factor(nosql.df$Database,
levels=c("MongoDB","Cassandra","Redis","HBase","CouchDB",
"Neo4j","Riak","MarkLogic","Couchbase","DynamoDB"))
gg <- ggplot(data=nosql.df, aes(x=Quarter, y=Index))
gg <- gg + geom_point(aes(color=Quarter), size=3)
gg <- gg + facet_grid(Database~.)