collapse_demog_dimension: Collapse a 'demog_change_component_df' object across...

View source: R/S3_classes_demog_change_component_utility_functions.R

collapse_demog_dimensionR Documentation

Collapse a demog_change_component_df object across demographic dimension(s)

Description

This function conveniently collapses objects across the demographic dimension(s) specified in by_dimensions. The “value” column is aggregated using function FUN. Columns corresponding to by_dimensions are dropped. If you want to aggregate other columns, or complete collapsing over a dimension is not desired, use aggregate, or similar.

Usage

collapse_demog_dimension(
  x,
  FUN = "sum",
  ...,
  by_dimensions = demog_change_component_dims(x),
  collapse_dimensions = NULL,
  out_class = c("demog_change_component_df", "data.frame")
)

Arguments

x

An object inheriting from demog_change_component_df.

FUN

A function to use to aggregate the “value” column of x; found by match.fun.

...

Passed to aggregate.data.frame. Must not include arguments named X, by, or FUN.

by_dimensions

A character vector (not a list) of demographic “dimensions” to aggregate over; see “Details”).

out_class

The class of the object to be returned (specifically the first element of the vector returned by class). See “Setting the class of the output”.

Details

Argument by_dimensions is a character vector and can be any of the allowed demographic “dimensions” such as “age”, “time”, “sex” (you can see the full list by calling ccmppWPP:::get_all_allowed_dimensions). The result will have values completely collapsed over the given dimension. E.g., if by_dimensions = "age" then column value in the result will contain the original values aggregated over all remaining dimensions, where aggregation is done by function FUN.

Value

A data frame.

Setting the class of the output

Collapsing a demog_change_component_df object will likely make it an invalid member of its class. By default, the function will attempt to return a demog_change_component_df. If this fails a data.frame will be returned with a warning.

Author(s)

Mark Wheldon

See Also

aggregate, link{abridge} demog_change_component_df


markalava/ccmppWPP documentation built on April 21, 2022, 12:36 a.m.