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.

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).

Value

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

Details

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

Examples

# load example data testData <- january2018 # apply categories testData <- cs_crime_cat(testData,var = crime, newVar = crimeCat, output = "numeric") # preview categories table(testData$crimeCat)
#> #> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #> 22 18 111 314 232 1110 266 17 196 18 47 7 59 309 121 3 #> 17 18 20 21 22 24 25 26 #> 9 160 1 15 6 55 50 679
# apply categories testData <- cs_crime_cat(testData,var = crime, newVar = crimeCat, output = "factor") # preview categories table(testData$crimeCat)
#> #> Homicide #> 22 #> Rape #> 18 #> Robbery #> 111 #> Aggravated Assault #> 314 #> Burgalry #> 232 #> Larceny #> 1110 #> Motor Vehicle Theft #> 266 #> Arson #> 17 #> Other Assaults #> 196 #> Forgery and Counterfeiting #> 18 #> Fraud #> 47 #> Embezzlement #> 7 #> Stolen Property #> 59 #> Vandalism #> 309 #> Weapons #> 121 #> Prostitution and Commercialized Vice #> 3 #> Sex Offenses #> 9 #> Drug Abuse Violations #> 160 #> Gambling #> 0 #> Offenses Against the Family and Children #> 1 #> Liquor Laws #> 15 #> Drunkeness #> 6 #> Disorderly Conduct #> 0 #> Vagrancy #> 55 #> All Other Offenses #> 50 #> Suspicion #> 679 #> Curfew and Loitering Laws-Persons under 18 #> 0 #> Runaways-Persons under 18 #> 0
# apply categories testData <- cs_crime_cat(testData,var = crime, newVar = crimeCat, output = "string") # preview categories table(testData$crimeCat)
#> #> Aggravated Assault #> 314 #> All Other Offenses #> 50 #> Arson #> 17 #> Burgalry #> 232 #> Drug Abuse Violations #> 160 #> Drunkeness #> 6 #> Embezzlement #> 7 #> Forgery and Counterfeiting #> 18 #> Fraud #> 47 #> Homicide #> 22 #> Larceny #> 1110 #> Liquor Laws #> 15 #> Motor Vehicle Theft #> 266 #> Offenses Against the Family and Children #> 1 #> Other Assaults #> 196 #> Prostitution and Commercialized Vice #> 3 #> Rape #> 18 #> Robbery #> 111 #> Sex Offenses #> 9 #> Stolen Property #> 59 #> Suspicion #> 679 #> Vagrancy #> 55 #> Vandalism #> 309 #> Weapons #> 121