state_to_region: Create region variable from state input

View source: R/state_to_region.R

state_to_regionR Documentation

Create region variable from state input

Description

This function works with title case names of the 50 states and D.C., as well as with all caps 2-letter abbreviations with and without periods (e.g., NJ and N.J.). Default regions are defined by the U.S. Census.

Usage

state_to_region(
  data,
  state.var = state,
  region.var = region,
  factorize = TRUE,
  region.levels = c("Northeast", "Midwest", "South", "West")
)

Arguments

data

A data frame or data frame extension (e.g. a tibble)

state.var

Variable containing state values. Defaults to state

region.var

Variable to be created containing regions. Defaults to region

factorize

A logical evaluation to TRUE or FALSE indicating whether to make the region.var a factor. Defaults to TRUE

region.levels

An optional vector of the unique values (as character strings) that region.var might have taken. Defaults to c("Northeast", "Midwest", "South", "West")

Value

A data frame

Examples

USArrests |> tibble::rownames_to_column("us_state") |>
state_to_region(us_state, us_region)

Faunalytics/faunalytics documentation built on Nov. 2, 2024, 12:05 a.m.