Skip to content

masking

apply_cond

apply_cond

Description

Takes a pandas DataFrame and a condition, which can be a string, dictionary, or callable, and applies the condition to the DataFrame using eval or apply accordingly.

Usage

apply_cond(df, cond)

Arguments

Argument Description
df DataFrame. A pandas DataFrame containing the data on which the condition will be applied.
cond MaskCondition. The condition to be applied on the dataframe. Can be either a string, a dictionary, or a callable function.

Return Value

DataFrame. Dataframe evaluated at the mask condition.

Mask

Description

Class to define masks with conditions and weights to apply to DataFiles

Methods

Public Methods

Method new()

Create a new mask object

Usage

Mask$new(where = NULL, use = NULL, weight = NULL, other = NaN, comment = "")

Arguments:

  • where MaskCondition | listMaskCondition, optional. Where the mask should be applied.
  • use MaskCondition | listMaskCondition, optional. Condition on where to use the masks.
  • weight Numeric | Character | listNumeric | Character, optional. Weights to apply.
  • other Numeric, optional.
  • comment Character, optional. Comment.

Method matches()

Check if a mask matches a dataframe by verifying if all 'where' conditions match across all rows.

Usage

Mask$matches(df)

Arguments:

  • df DataFrame. Dataframe to check for matches.

Returns:

Logical. If the mask matches the dataframe.

Method get_weights()

Apply weights to the dataframe

Usage

Mask$get_weights(df)

Arguments:

  • df (Dataframe): Dataframe to apply weights on

Returns:

Dataframe. Dataframe with applied weights

Method clone()

The objects of this class are cloneable with this method.

Usage

Mask$clone(deep = FALSE)

Arguments:

  • deep Whether to make a deep clone.

read_masks

read_masks

Description

Reads YAML files containing mask specifications from multiple databases and returns a list of Mask objects.

Usage

read_masks(variable)

Arguments

Argument Description
variable Character. Variable to be read.

Return Value

List. List with masks for the variable.