Description Usage Arguments Details Value See Also Examples
View source: R/miscellaneous-functions.R
Reformat a vector of age-group labels, so that it matches the format
expected by functions such as Counts
and
Values
.
1 2 3 | cleanAgeGroup(age)
cleanAgeGroupConc(age)
|
age |
A vector of age labels. |
cleanAgeGroup
strips off spaces or other symbols,
converts text to numbers, and otherwise tries to guess at
the age-group labels.
It is common for age groups to be coded using only the first
year, so that, for instance, 0
, 1
, 5
,
...
, 100
is short for "0"
,
"1-4"
, "5-9"
, ...
, "100+"
.
cleanAgeGroup
interprets a vectorage
as a set of age-group labels if the unique values from age
,
once sorted, form a sequence, 0, 5, 10, ...
or
0, 1, 5, 10, ...
.
cleanAgeGroup
does the reformatting. cleanAgeGroupConc
constructs a {Concordance}
between the old and
new age-group labels.
cleanAgeGroup
is suitable for interactive use, or for
one-off analyses, where the data will not change in future.
Using cleanAgeGroupConc
may be safer in production
code where the data may change. The workflow is as follows:
Use a vector of age labels to construct a concordance.
Store the concordance.
When new data arrives, use function
translate
, plus the stored concordance,
to clean the age data.
The advantange of this work flow is that translate
will throw an error if it strikes an age label that it
does not recognize.
A character vector of reformatted age labels.
ageToAgeGroup
converts exact
ages into age groups.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | x1 <- c("0 - 4 years", "90 plus years", "25 - 29 years")
x2 <- c("10 to 19 Yr", "80 years and over")
x3 <- c(10, 0, 5, 1, 5)
x4 <- c("5--9", "10plus", "0--4")
x5 <- c("10plus", "10plus", "5--9", "5--9")
## Use cleanAgeGroup directly
cleanAgeGroup(x1)
cleanAgeGroup(x2)
cleanAgeGroup(x3)
## Set up concordance and use that
conc <- cleanAgeGroupConc(x4)
translate(x5, concordance = conc)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.