Random points in USA - average resident, facility, BG, block, or square mile
Source:R/testpoints_n.R
testpoints_n.Rd
Get data.table of Random Points (lat lon) for Testing/ Benchmarking/ Demos, weighted in various ways. The weighting can be specified so that each point reflects the average EPA-regulated facility, blockgroup, block, place on the map, or US resident.
Usage
testpoints_n(
n = 10,
weighting = c("frs", "pop", "area", "bg", "block"),
region = NULL,
ST = NULL,
validonly = TRUE,
dt = TRUE
)
Arguments
- n
Number of points needed (sample size)
- weighting
word indicating how to weight the random points (some synonyms are allowed, in addition to those shown here):
Note the default is frs, but you may want to use pop even though it is slower.
pop or people (slow) = Average Person: random person among all US residents (block point of residence per 2020 Census)
frs or facility = Average Facility: random EPA-regulated facility from actives in Facility Registry Service (FRS)
bg = Average Blockgroup: random US Census block group (internal point like a centroid)
block = Average Block: random US Census block (internal point like a centroid)
area or place = Average Place: random point on a map (internal point of avg blockgroup weighted by its square meters size)
- region
optional vector of EPA Regions (1-10) to pick from only some regions.
- ST
optional, can be a character vector of 2 letter State abbreviations to pick from only some States.
- validonly
return only points with valid lat/lon coordinates. Defaults to TRUE.
- dt
logical, whether to return a data.table (DEFAULT) instead of normal data.frame
Value
data.frame or data.table with columns lat, lon in decimal degrees, and any other columns that are in the table used (based on weighting)
Examples
mapfast(testpoints_n(300, ST = c('LA','MS')) )
#> Including only these States:
#> REGION ST statename
#> 1 6 LA Louisiana
#> 2 4 MS Mississippi
#> Warning: 1 fips had invalid number of characters (digits) or were NA values
#> Warning: NA returned for 1 values that failed to match
#> Warning: Some latitude / longitude were provided that are not found in any state
# \donttest{
n=2
for (d in c(TRUE,FALSE)) {
for (w in c('frs', 'pop', 'area', 'bg', 'block')) {
cat("n=",n," weighting=",w, " dt=",d,"\n\n")
print(x <- testpoints_n(n, weighting = w, dt = d)); print(class(x))
cat('\n')
}
}
#> n= 2 weighting= frs dt= TRUE
#>
#> Key: <REGISTRY_ID>
#> lat lon REGISTRY_ID PRIMARY_NAME NAICS SIC
#> <num> <num> <char> <char> <char> <char>
#> 1: 33.20615 -86.30879 110015328368 DR WILLIAMS ESTATE
#> 2: 33.98334 -117.34027 110066602938 SHELL IOWA AVENUE
#> PGM_SYS_ACRNMS sitenumber
#> <char> <int>
#> 1: RCRAINFO:ALR000029520 1
#> 2: CA-ENVIROVIEW:198131 2
#> [1] "data.table" "data.frame"
#>
#> n= 2 weighting= pop dt= TRUE
#>
#> Key: <blockid>
#> blockid lat lon bgid blockwt block_radius_miles sitenumber
#> <int> <num> <num> <int> <num> <num> <int>
#> 1: 1659891 33.58177 -85.10405 59173 0.02167712 0 1
#> 2: 4845922 40.66769 -73.95963 145599 0.35954475 0 2
#> [1] "data.table" "data.frame"
#>
#> n= 2 weighting= area dt= TRUE
#>
#> Error in sample.int(blockgroupstats[, .N], size = n, replace = FALSE, prob = blockgroupstats$area): length(n) == 1L is not TRUE
# }