Skip to content

Instantly share code, notes, and snippets.

Anthony Damico ajdamico

Block or report user

Report or block ajdamico

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ajdamico
ajdamico / wwow.R
Created Dec 7, 2014
world without water
View wwow.R
# setwd( "C:/My Directory/wwow/" )
path.to.7z <- normalizePath( "C:/Program Files (x86)/7-zip/7z.exe" )
library(stringr)
library(downloader)
library(raster)
library(rasterVis)
source_url(
@ajdamico
ajdamico / import SAS ASCII file into R with SAS INPUT text file
Created May 4, 2010
import SAS ASCII file into R with SAS INPUT text file
View import SAS ASCII file into R with SAS INPUT text file
##select file containing SAS input procedure
SASinput <- readLines(file.choose())
##find the first INPUT line
firstline<-min(grep("INPUT @1",toupper(SASinput)))
##find the first semicolon ending that input line
a<-grep(";",toupper(SASinput))
lastline<-min(a[a>firstline])
@ajdamico
ajdamico / calculate your ten thousandth day on earth with R
Created Jul 24, 2010
calculate your ten thousandth day on earth with R
View calculate your ten thousandth day on earth with R
#replace my birthday with yours
birthday <- strptime(c("8.18.1982"), format = "%m.%d.%Y", tz="EST")
#r counts everything in seconds, so this code multiplies by 60 seconds in a minute, 60 minutes in an hour, 24 hours in a day.
days <- function(u) {
x <- u * 60 * 60 * 24
return(x)
}
#change these numbers to whichever days you'd like to see, separated by commas
@ajdamico
ajdamico / download the medical expenditure panel survey.R
Created Nov 9, 2010
download all publicly-available data files for every year of the Medical Expenditure Panel Survey
View download the medical expenditure panel survey.R
library(RCurl)
setwd("R:\\Medical Expenditure Panel Survey\\Data")
#input all available MEPS public use file numbers
year <- c(1996:2008)
consolidated <- c(12,20,28,38,50,60,70,79,89,97,105,113,NA)
conditions <- c("06r",18,27,37,52,61,69,78,87,96,104,112,NA)
jobs <- c("07",19,25,32,40,56,63,74,83,91,100,108,116)
prpf <- c(24,47,47,47,47,57,66,76,88,95,103,111,119)
@ajdamico
ajdamico / multicore win64.R
Created Dec 10, 2010
run multicore processing in the windows 64 bit version of R
View multicore win64.R
library(snowfall)
bigProcess <- function( x ) {
mean( replicate ( 10^6 , max( rnorm( 100 , x ) ) ) )
}
#run the function twice in parallel
start <- Sys.time()
sfInit(cpus=2,type='SOCK',parallel=TRUE)
sfSapply( c(1,5) , bigProcess )
@ajdamico
ajdamico / furman intro to r lecture.R
Created Apr 1, 2011
introduction to r lecture notes - furman center for real estate and urban policy
View furman intro to r lecture.R
#three reasons to use R-
#it's free
#it's open source- package system
#it's a programming language for statistics.
x <- 1:5
@ajdamico
ajdamico / determine what pecent of fractions are non-repeating.R
Created Aug 7, 2011
calculate the percent of fractions that are repeating vs. non-repeating with R
View determine what pecent of fractions are non-repeating.R
# calculate the percent of fractions that are repeating vs. non-repeating
# install stringr if you don't already have it
#install.packages("stringr")
library( stringr )
options( digits=22 )
# this program looks at..
# 1/1, 1/2, 1/3, 1/4.. up to 1/x
@ajdamico
ajdamico / analyzing big survey data with limited computing resources.R
Created Aug 18, 2011
Convert large government survey data files into a SQLite database and then produce the principle set of statistical estimates and accompanying error terms, with limited RAM.
View analyzing big survey data with limited computing resources.R
########################################
###read large csv into SQL DB
########################################
#set to the number of GB of RAM on computer
gbram <- 0.5
#set to CSV file directory
setwd("C:\\American Community Survey\\2009\\")
@ajdamico
ajdamico / download all files from an FTP site.R
Created Sep 19, 2011
download fifty years of National Health Interview Survey documentation PDFs
View download all files from an FTP site.R
#install RCurl on your version of R if you don't already have it
#just run this once
#install.packages("RCurl")
#program start
#load the RCurl package
library(RCurl)
#set your output folder - this is where the pdfs will get saved
setwd("R:/National Health Interview Survey/documentation")
@ajdamico
ajdamico / NHIS download matrix.R
Created Sep 30, 2011
download every file for every year of the National Health Interview Survey and convert them all to csv and stata files
View NHIS download matrix.R
#load necessary libraries
library(stringr)
library(foreign)
library(survey)
library(RCurl)
#set the temporary directory to download all files to!
setwd("s:/temp")
You can’t perform that action at this time.