Learn R Programming

gsClusterDetect (version 1.0.0)

tract_generator: Generate Census Tract Centroids for a State

Description

Pulls census tracts using tigris, computes tract centroids, and returns a three-column data.table with GEOID, latitude, and longitude.

Usage

tract_generator(st, county = NULL, use_cache = TRUE, ...)

Value

A data.table with columns:

geoid

11-digit tract GEOID (state(2) + county(3) + tract(6))

latitude

Centroid latitude in WGS84

longitude

Centroid longitude in WGS84

Arguments

st

Character scalar; either a 2-digit state FIPS code (for example, "24") or a 2-letter USPS abbreviation (for example, "MD").

county

A three-digit FIPS code (string) of the county or counties to subset on. This can also be a county name or vector of names.

use_cache

a boolean, defaults to TRUE, to set tigris option to use cache

...

arguments to be passed on to tigris::tracts()

Examples

Run this code
md_tracts <- tract_generator("24")
md_tracts2 <- tract_generator("MD")
howard_county_tracts <- tract_generator("MD", county = "027")
head(md_tracts)

Run the code above in your browser using DataLab