# hadley said this was ok
utils::globalVariables(c('measure', 'sex', 'age', 'value'))
#' Select lifetable from dataset.
#'
#' Select from a lifetable dataset by year and state.
#'
#' Performs a simple filter and select to extract lifetable data by year and
#' location code (e.g. state).
#'
#' @param df a data.frame such as abs_lt supplied by this package.
#' @param year integer year specifying the first year of the lifetable,
#' interpretation depends on dataset, i.e.
#' \describe{
#' \item{ABS (abs_lt)}{2002 refers to the 2002-2004 lifetable}
#' }
#' @param loc abbreviation of location to retrieve, default value is 'AU' for
#' the national life-table, other valid values depend on the dataset,
#' \describe{
#' \item{ABS (abs_lt)}{'ACT', 'NSW', 'NT', 'QLD', 'SA', 'TAS', 'VIC' and
#' 'WA'}
#' }
#' @return data.frame of lifetable in a long format: age, sex, measurement type
#' (e.g. 'lx', 'qx' etc.) and the value.
#'
#' @examples
#' select_lifetable(abs_lt, 2010, 'QLD')
#'
#' @importFrom plyr arrange
#' @export
select_lifetable <- function(df,
year=2013,
loc='AU') {
arrange(df[df$year==year & df$loc==loc,
c('measure',
'sex',
'age',
'value')],
measure, sex, age, value)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.