Skip to content

Instantly share code, notes, and snippets.

@ajdamico
ajdamico / most recent 100 books posted to paperbackswap.R
Created May 5, 2012 22:48
webscrape the ISBN-10 values of the 100 most recent books posted to paperbackswap.com
library(XML)
url <- "http://www.paperbackswap.com/api/v1/index.php?RequestType=RecentlyPosted&Limit=100"
u <- xmlParse( url )
v <- getNodeSet( u , "/Response/Books/Book/ISBN-10" )
w <- sapply( v , xmlValue )
@ajdamico
ajdamico / let it be.R
Created March 6, 2012 04:44
let R sing the beatles
title = "Let it be"
wow = "words of wisdom"
Verse.1 =
c( "When I find myself in times of trouble" ,
"Mother Mary comes to me" ,
paste( "Speaking" , wow ) ,
title )
@ajdamico
ajdamico / listlabeling.R
Created October 31, 2011 21:52
roger peng's listlabeling challenge
#roger peng's listlabeling challenge from
#http://simplystatistics.tumblr.com/post/11988685443/computing-on-the-language
#create three example variables for a list
x <- 1
y <- 2
z <- "hello"
#create the function
makeList <- function(...) {
@ajdamico
ajdamico / analyzing big survey data with limited computing resources.R
Created August 18, 2011 11:05
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.
########################################
###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 / determine what pecent of fractions are non-repeating.R
Created August 7, 2011 08:25
calculate the percent of fractions that are repeating vs. non-repeating with 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 / furman intro to r lecture.R
Created April 1, 2011 15:38
introduction to r lecture notes - furman center for real estate and urban policy
#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 / multicore win64.R
Created December 10, 2010 21:58
run multicore processing in the windows 64 bit version of 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 / calculate your ten thousandth day on earth with R
Created July 24, 2010 18:26
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 / import SAS ASCII file into R with SAS INPUT text file
Created May 4, 2010 22:11
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 / wwow.R
Created December 7, 2014 19:00
world without water
# 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(