acs.translate: Rewrite values in ACS PUMS data

Description Usage Arguments Value Examples

View source: R/acs.translate.R

Description

Many variables in the ACS PUMS data are integer-coded categorical values. For readability, we often want to replace these with strings or factors. acs.translate takes the values in the variable field and substitutes elements of new for the corresponing element of old. The result is a factor with the levels in the order of level.order if used, or in the order of unique(new) otherwise.

Usage

1
acs.translate(x, field, old, new, level.order = NULL)

Arguments

x

a data frame of PUMS data

field

string name of the field in x to translate

old

vector of the unique values in x$field

new

vector of replacement values (strings). Must be same length as old, but values do not have to be unique (see example).

level.order

order to give to factor levels, if used. Default NULL uses ordering of unique(new)

Value

factor vector of same length as x$field with values from new substituted for the originals

Examples

1
2
3
4
5
6
7
8
9
new.vals <- c('own','own','rent', 'rent', 'vacant')
wa.house16$Tenure <- acs.translate(wa.house16, 'TEN', c(1:4, NA), new.vals)
group.count(wa.house16, 'HH.Count', 'Tenure')

# Strings would not be in this order
in.order <- c('vacant', 'own', 'rent')
wa.house16$Tenure <- acs.translate(wa.house16, 'TEN', c(1:4, NA),
                                   new.vals, level.order=in.order)
group.count(wa.house16, 'HH.Count', 'Tenure')

davidthaler/PUMSutils documentation built on July 13, 2019, 9:58 a.m.