{{ message }}

Instantly share code, notes, and snippets.

🏠
Working from home

# Anirudh Jayaraman anirudhjayaraman

🏠
Working from home
Last active Jun 14, 2021
14.74x Foundation of Development Policy (Homework Assignment 02)
View HW02.R
 # Set working directory to local directory where the data is kept setwd("~/IGIDR/Development Economics - MIT/Homework Assignment 02") # read data migueldata = read.csv("ted_miguel_worms.csv", header = TRUE) attach(migueldata) # Question 6 # How many observations are there per pupil? (Enter a whole number of 0 or higher)? length(migueldata\$pupid) length(unique(migueldata\$pupid)) # Question 7
Created Dec 12, 2015
Solution to HackerRank Problem - Sherlock and the Beast
View sherlockandthebeast.py
 #!/bin/python import sys def combinations_sum(n): k = n/2 combs = [] answers = [] for i in range(0,k+1): a,b = i, n-i
Created Nov 12, 2019
Linear regression implementation using linear algebra in R
View lm_linear_algebra.R
 ### Linear Regression Using lm() ---------------------------------------- data("swiss") dat <- swiss linear_model <- lm(Fertility ~ ., data = dat) summary(linear_model) # Call: # lm(formula = Fertility ~ ., data = dat) #
Last active Feb 22, 2021
Karatsuba Multiplication
View karatsuba.py
 def karatsuba(x,y): """Function to multiply 2 numbers in a more efficient manner than the grade school algorithm""" if len(str(x)) == 1 or len(str(y)) == 1: return x*y else: n = max(len(str(x)),len(str(y))) nby2 = n / 2 a = x / 10**(nby2) b = x % 10**(nby2)
Last active Feb 16, 2021
Implementing Undirected Graphs in Python
View graphUndirected.py
 class Vertex: def __init__(self, vertex): self.name = vertex self.neighbors = [] def add_neighbor(self, neighbor): if isinstance(neighbor, Vertex): if neighbor.name not in self.neighbors: self.neighbors.append(neighbor.name) neighbor.neighbors.append(self.name)
Last active Feb 3, 2021
Python code for the Quick Sort Algorithm
View quicksort.py
 def quicksort(x): if len(x) == 1 or len(x) == 0: return x else: pivot = x[0] i = 0 for j in range(len(x)-1): if x[j+1] < pivot: x[j+1],x[i+1] = x[i+1], x[j+1] i += 1
Created Oct 7, 2017
View AirPassengers.Rmd
 --- title: "ARIMA Modeling in R" output: html_document --- Let's start off by loading relevant R libraries! ```{r include = FALSE} library(tseries) library(zoo) library(forecast)
Last active Aug 5, 2020
Merge Sort Algorithm Implimentation
View mergesort.py
 # Code for the merge subroutine def merge(a,b): """ Function to merge two arrays """ c = [] while len(a) != 0 and len(b) != 0: if a[0] < b[0]: c.append(a[0]) a.remove(a[0]) else:
Last active Jul 17, 2020
View rice_strucchange.R
 library(xlsx) library(forecast) library(tseries) library(strucchange) ## load the data from a CSV or Excel file. This example is done with an Excel sheet. prod_df <- read.xlsx(file = 'agricultural_productivity.xls', sheetIndex = 'Sheet1', rowIndex = 8:65, colIndex = 2, header = FALSE) colnames(prod_df) <- c('Rice') ## store rice data as time series objects rice <- ts(prod_df\$Rice, start=c(1951, 1), end=c(2008, 1), frequency=1)
Last active Jul 8, 2020
View remove_missing_levels.R
 remove_missing_levels <- function(fit, test_data) { library(magrittr) # https://stackoverflow.com/a/39495480/4185785 # drop empty factor levels in test data test_data %>% droplevels() %>% as.data.frame() -> test_data