# NOT RUN {
## ?setApiKey before running examples
schedulerMMDD <- scheduler()
## select random county and sample one station from each 0.01 arc degrees
## (roughly 1km^2 at the equator)
scrape(schedulerMMDD, c("GEOID", "ZCTA5"), size=c(1, NA, 1), strata=c(NA, NA, "GRID"),
weight="COPOP", cellsize=c(NA, 0.01))
## same, but limit sampling to southeastern US
data(zctaRel)
SE <- c("01", "05", "12", "13", "21", "22", "24", "28", "37", "45", "47", "51", "54")
scrape(schedulerMMDD, c("GEOID", "ZCTA5"), size=c(1, NA, 1), strata=c(NA, NA, "GRID"),
weight="COPOP", cellsize=c(NA, 0.01), sampleFrame=zctaRel[zctaRel $STATEFP %in% SE, ])
## select two states and in each state select a 1 arc degree area (roughly
## 100km^2 at the equator) and sample five zip codes, each stratified into
## 0.01 arc degree areas
scrape(schedulerMMDD, c("STATEFP", "GRID", "ZCTA5"), size=c(2, 1, 5, 1),
strata=c(NA, "STATEFP", "GRID", "GRID"), cellsize=c(1, NA, 0.01))
## periodically resample one location
sampleFrame <- with(zctaRel, zctaRel[GEOID==sample(GEOID, 1, weight=COPOP), ])
plan(schedulerMMDD, '2 hours')
repeat {
scrape(schedulerMMDD, "ZCTA5", strata=c(NA, "GRID"), cellsize=0.01, sampleFrame=sampleFrame)
sync(schedulerMMDD) # sync schedule after each sample to wait for next scheduled sample
}
## stratify by rural and urban to ensure both types of areas recieve adequate representation
zctaRel $RURAL <- log(zctaRel $COPOP) < 10
scrape(schedulerMMDD, c("GEOID", "ZCTA5"), size=c(1, 8, 1), strata=c("RURAL", "RURAL", "GRID"),
weight="COPOP", cellsize=c(NA, 0.01), sampleFrame=zctaRel)
# }
Run the code above in your browser using DataCamp Workspace