Learn R Programming

UScensus2010 (version 0.20.0)

city: Selects one or more CDP(s) from a given state

Description

city allows the user to pull out the polygon and metadata of one or more CDPs for any given state by name.

Usage

city(name, state, statefips = FALSE, sp.object = NULL, proj = NULL )

Arguments

name

a character string, takes the value of a string or string vector and has to be the exact name or names of CDP(s). (If you are unsure of the exact name a quick way to find it is to load the library(UScensus2010cdp) and pull out the list of names for the state you are interested in (see example).Note: if statefips=TRUE then this must be a CDP fips code.

state

a character string, can either be the full name (e.g. "oregon"), the abbreviation (e.g. "or"), or the FIPS code (e.g. "41")-- note that if you are using the FIPS code you have to change statefips to TRUE.

statefips

logical, by default statefips=FALSE, change to TRUE when providing state with a FIPS code.

sp.object

SpatialPolygonsDataFrame, default NULL, allows the user to provide an sp object in which to perform this operation; primarily for use with demographics.add.

proj

CRS-class, takes a CRS object (e.g. CRS("+proj=utm +zone=10 +datum=NAD83") ); This is simply a wrapper for the spTransform function in rgdal . WARNING requires rgdal package.

Value

An object of class SpatialPolygonsDataFrame.

References

Zack W. Almquist (2010). US Census Spatial and Demographic Data in R: The UScensus2000 Suite of Packages. Journal of Statistical Software, 37(6), 1-31. https://www.jstatsoft.org/v37/i06/.

Census 2010 Summary File 1 [name of state1 or United States]/prepared by the U.S. Census Bureau, 2011. https://www.census.gov/prod/cen2000/doc/sf1.pdf

Examples

Run this code
# NOT RUN {
##Load oregon.cdp10 data 
data(oregon.cdp10)

##look at the list of oregon CDP names in alphabetic order
oregon.cdp10$name[order(oregon.cdp10$name)]

##grab the CDP of Portland, OR
portland<-city(name="portland",state="or")


##plot the polygon of Portland, OR
plot(portland)
title("Portland, OR")
# }

Run the code above in your browser using DataLab