name_to_fips: Get FIPS or CBSA codes from county or metropolitan area names

Description Usage Arguments Value See Also Examples

View source: R/utils.R

Description

Look up FIPS or CBSA codes by county or metropolitan area names, respectively; these functions are based on grep(), and hence allow for regular expressions.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
name_to_fips(
  name,
  ignore.case = FALSE,
  perl = FALSE,
  fixed = FALSE,
  ties_method = c("first", "all"),
  state = NULL
)

name_to_cbsa(
  name,
  ignore.case = FALSE,
  perl = FALSE,
  fixed = FALSE,
  ties_method = c("first", "all"),
  state = NULL
)

Arguments

name

Vector of county or metropolitan area names to look up.

ignore.case, perl, fixed

Arguments to pass to grep(), with the same defaults as in the latter function. Hence, by default, regular expressions are used; to match against a fixed string (no regular expressions), set fixed = TRUE.

ties_method

If "first", then only the first match for each name is returned. If "all", then all matches for each name are returned.

state

Two letter state abbreviation (case insensitive) indicating a parent state used to restrict the search. For example, when state = "NY", then name_to_fips() searches only over only counties lying in New York state, whereas name_to_cbsa() searches over the metropolitan areas lying, either fully or partially (as a metropolitan area can span several states), in New York state. If NULL, the default, then the search is performed US-wide (not restricted to any state in particular).

Value

A vector of FIPS or CBSA codes if ties_method equals "first", and a list of FIPS or CBSA codes otherwise.

See Also

state_fips_to_name(), cbsa_to_name()

Examples

1
2
3
4
5
name_to_fips("Allegheny")
name_to_cbsa("Pittsburgh")
name_to_fips("Miami")
name_to_fips("Miami", ties_method = "all")
name_to_fips(c("Allegheny", "Miami", "New "), ties_method = "all")

covidcast documentation built on May 4, 2021, 9:08 a.m.