Description Usage Arguments Value Examples
View source: R/acs.translate.R
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.
1 | acs.translate(x, field, old, new, level.order = NULL)
|
x |
a data frame of PUMS data |
field |
string name of the field in x to translate |
old |
vector of the unique values in |
new |
vector of replacement values (strings).
Must be same length as |
level.order |
order to give to factor levels, if used.
Default NULL uses ordering of |
factor vector of same length as x$field
with values from
new
substituted for the originals
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')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.