Skip to content

Instantly share code, notes, and snippets.

View raffdoc's full-sized avatar

Rafik Margaryan raffdoc

View GitHub Profile
@schaunwheeler
schaunwheeler / xlsxToR.r
Last active December 11, 2020 16:41
Import an xlsx file into R by parsing the file's XML structure.
# The MIT License (MIT)
#
# Copyright (c) 2012 Schaun Jacob Wheeler
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@Ram-N
Ram-N / google-research.R
Last active June 11, 2019 00:54
Google Research Grant recipients.
rm(list=ls())
library(ggplot2)
df <- read.csv("~/RStats/data/ResearchGrants2013.csv", stringsAsFactors=F, strip.white=T)
df <- df[,-6] #get rid of the trailing blank
dim(df)
#quick check
unique(df$Research.Category)
table(df$Research.Category)
@mollietaylor
mollietaylor / map-new-legend.R
Created September 29, 2013 23:02
Custom Legend in R
library(OIdata)
library(RColorBrewer)
library(classInt)
# load state data from OIdata package:
data(state)
# set constants:
nclr <- 8 # number of bins
min <- 0 # theoretical minimum
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~.)

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)
}
@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
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
}
@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.

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
@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