Skip to content

Instantly share code, notes, and snippets.

View Ram-N's full-sized avatar

Ram Narasimhan Ram-N

View GitHub Profile
@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)
@Ram-N
Ram-N / ColNames.R
Created May 30, 2018 17:58
Using paste0 with length=option
i <- 1:50
b <- 1:5
ColNames <- paste0("X_", i, "_", rep(b, each=length(i)))
@Ram-N
Ram-N / ColNames.R
Created May 30, 2018 17:58
Using paste0 with length=option
i <- 1:50
b <- 1:5
ColNames <- paste0("X_", i, "_", rep(b, each=length(i)))
df[, !(colnames(df) %in% c("x","bar","foo"))]
import pandas as pd
df = pd.DataFrame([
['2018-03-11', '11:03', 86],
['2018-03-14', '09:27', 43],
['2018-03-14', '12:08', 22],
['2018-03-15', '03:13', 140],
['2018-03-17', '18:06', 10]],
columns=['Date','Time','Duration'])
@Ram-N
Ram-N / Flowfree_lib.R
Last active April 5, 2018 01:39
Using R and the library lpSoveAPI to find solutions to FlowFree boards. Note that the side has to be specified. There are 3 problems (*.csv) files, included for testing the testing. Create your own csv for other problems.
rm(list=ls())
library(lpSolveAPI)
#utility functions
getColnum <- function(cell, color, edge) {
# return(4*(cell-1)+edge)
celloffset <- (cell-1)*4*num.colors
coloroffset <- (color-1)*4
return(celloffset+coloroffset+edge)
}
@Ram-N
Ram-N / facet_annotate.R
Last active January 12, 2018 05:58
Adding Annotations to Facet_Grid
mtcars[, c("cyl", "am", "gear")] <- lapply(mtcars[, c("cyl", "am", "gear")], as.factor)
p <- ggplot(mtcars, aes(mpg, wt, group = cyl)) +
geom_line(aes(color=cyl)) +
geom_point(aes(shape=cyl)) +
facet_grid(gear ~ am) +
theme_bw()
p
@Ram-N
Ram-N / data_manipu.R
Created January 5, 2018 05:20
TIDYR - gather, unite and spread.
library(tidyr)
df <- data.frame(
MKT=c("ABIORD", "ABIBOS", "GCFPQR", "ABIORD", "ABIBOS", "GCFPQR", "ABIORD", "ABIBOS", "GCFPQR"),
VERSION=c(1,2,3,4,1,2,3,4,1),
REVERSALS=c(7,6,7,7,7,6,7,7, 9),
NEIGH=c(1,2.3,3.3,4,3.3,2,1,3.3,4.3),
DIFFMETRIC=c(1.1,2.1,3.1,4.1,3.1,2.1,1.1,3.1,4.1))
@Ram-N
Ram-N / Loop Through
Created June 12, 2017 23:40
24_game_puzzle
def common_elements(list1, list2):
return list(set(list1) & set(list2))
import itertools
fileidx = 1
for x,y in itertools.combinations(cards, 2):
match = common_elements(x, y)
print(len(match), match)
if len(match):
library(dplyr)
df1 <- mtcars
df2 <- filter(mtcars, mpg >19)
names(df1)
col1 <- 'qsec'
val1 <- 15.5
col2 <- 'qsec'