age2int {HMDHFDplus} | R Documentation |
age2int()
convert the Age column from standard HMD or HFD tables to integer
Description
Long the bane of many an HMD/HFD user is that the age column must be read into R as a factor or character vector, yet we'd like to use it as integer or numeric. This function strips symbols that are used to indicate the open age groups ("12-","55+","110+"), and coerces to integer format. This function is called by HFDparse()
and HMDparse()
, and so forth.
Usage
age2int(Age)
Arguments
Age |
a vector of the Age column from and HMD or HFD data object that has been read directly into R. This may be a factor or character vector. |
Details
This function is written for the sake of various parse functions.
Value
the same age vector as a clean integer.
Note
original function submitted by Josh Goldstein, modified by Tim Riffe.
Examples
AgeTest <- c("12-","13","14","55+")
(AgeNew <- age2int(AgeTest))
AgeNew + .5 # sort of mid-interval
# also handles abrdiged ages properly:
AgeAbridged <- c("0","1-4","5-9","10-14")
age2int(AgeAbridged)
[Package HMDHFDplus version 2.0.3 Index]