Learn R Programming

HMDHFDplus (version 2.0.6)

age2int: 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)

Value

the same age vector as a clean integer.

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.

Examples

Run this code
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)

Run the code above in your browser using DataLab