This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(...) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#load necessary libraries | |
library(stringr) | |
library(foreign) | |
library(survey) | |
library(RCurl) | |
#set the temporary directory to download all files to! | |
setwd("s:/temp") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################## | |
###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\\") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#three reasons to use R- | |
#it's free | |
#it's open source- package system | |
#it's a programming language for statistics. | |
x <- 1:5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#warning: excludes the institutionalized population! | |
#install survey and foreign packages | |
#-- only run these lines of code the first time | |
#install.packages("foreign") | |
#install.packages("survey") | |
#designate each of the MEPS consolidated files - | |
consolidated_files <- c( 12 , 20 , 28 , 38 , 50 , 60 , 70 , 79 , 89 , 97 , 105 , 113 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |