make_value_ratio: Calculate the ratio of values in two data frames

View source: R/S3_classes_demog_change_component_utility_functions.R

make_value_ratioR Documentation

Calculate the ratio of values in two data frames

Description

The ratio of the “value” columns in the numerator (num) and denominator (denom) data frames is calculated and returned. num and denom are first merged on columns named by_vars_names and these columns are in the output, which is also a data frame.

Usage

make_value_ratio(num, denom, by_vars_names = NULL, all.x = TRUE, all.y = FALSE)

Arguments

num

A data frame with columns “by_vars_names” and “value”, holding the numerator values.

denom

Similar to num but holding the denominator values.

by_vars_names

Character vector of names of columns to merge by. By default, all columns except “value”. See also “Details”.

all.x

logical; if TRUE, then extra rows will be added to the output, one for each row in x that has no matching row in y. These rows will have NAs in those columns that are usually filled with values from y. The default is FALSE, so that only rows with data from both x and y are included in the output.

all.y

logical; analogous to all.x.

Details

When by_vars_names is NULL, if denom has column time_span and all entries are 0, “time_span” will be omitted from by_vars_names. Note: This only happens if by_vars_names is NULL.

Value

A data frame with columns “by_vars_names” and “value”, where the latter holds the ratio of “value”s in num and denom.

Author(s)

Mark Wheldon


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