cs_crime_cat: Categorize Crime

View source: R/categorize.R

cs_crime_catR Documentation

Categorize Crime

Description

The SLMPD data contains 5 or 6 digit codes to refer to specific categories of crime. cs_crime_cat transforms these into either string, factor, or simplified numeric categories like "murder" or "aggravated assault". This can be used on any police department's data where codes like 31111 (robbery with a firearm) or 142320 (malicious destruction of property) are used to identify crimes.

Usage

cs_crime_cat(.data, var, newVar, output)

Arguments

.data

A tibble or data frame

var

Name of variable with 5 or 6 digit crime codes

newVar

Name of output variable to be created with simplified categories

output

Type of output - either "string", "factor", or "numeric". If "numeric" is selected, the general UCR code will be returned (i.e. 1 for homicide, 3 for aggravated assault, etc.). Factor output will be returned in order of descending UCR code (i.e. beginning with homicide, which has a UCR code of 1).

Details

The categories used here are derived from the U.S. Federal Bureau of Investigation's Uniform Crime Reporting codes.

Value

A copy of the object with the new output variable appended to it.

Examples

# load example data
testData <- january2018

# apply categories
testData <- cs_crime_cat(testData,var = crime, newVar = crimeCat, output = "numeric")

# preview categories
table(testData$crimeCat)

# apply categories
testData <- cs_crime_cat(testData,var = crime, newVar = crimeCat, output = "factor")

# preview categories
table(testData$crimeCat)

# apply categories
testData <- cs_crime_cat(testData,var = crime, newVar = crimeCat, output = "string")

# preview categories
table(testData$crimeCat)


chris-prener/compStatR documentation built on Jan. 25, 2024, 10:03 p.m.