derive_var_merged_cat {admiral}R Documentation

Merge a Categorization Variable



This function is deprecated, please use derive_vars_merged() instead.

Merge a categorization variable from a dataset to the input dataset. The observations to merge can be selected by a condition and/or selecting the first or last observation for each by group.


  order = NULL,
  filter_add = NULL,
  mode = NULL,
  missing_value = NA_character_



Input dataset

The variables specified by the by_vars argument are expected.


Additional dataset

The variables specified by the by_vars, the source_var, and the order argument are expected.


Grouping variables

The input dataset and the selected observations from the additional dataset are merged by the specified by variables. The by variables must be a unique key of the selected observations. Variables from the additional dataset can be renamed by naming the element, i.e., ⁠by_vars = exprs(<name in input dataset> = <name in additional dataset>)⁠, similar to the dplyr joins.

Permitted Values: list of variables created by exprs()


Sort order

If the argument is set to a non-null value, for each by group the first or last observation from the additional dataset is selected with respect to the specified order.

Variables defined by the new_vars argument can be used in the sort order.

Permitted Values: list of expressions created by exprs(), e.g., exprs(ADT, desc(AVAL)) or NULL


New variable

The specified variable is added to the additional dataset and set to the categorized values, i.e., ⁠cat_fun(<source variable>)⁠.


Source variable


Categorization function

A function must be specified for this argument which expects the values of the source variable as input and returns the categorized values.


Filter for additional dataset (dataset_add)

Only observations fulfilling the specified condition are taken into account for merging. If the argument is not specified, all observations are considered.

Variables defined by the new_vars argument can be used in the filter condition.

Permitted Values: a condition


Selection mode

Determines if the first or last observation is selected. If the order argument is specified, mode must be non-null.

If the order argument is not specified, the mode argument is ignored.

Permitted Values: "first", "last", NULL


Values used for missing information

The new variable is set to the specified value for all by groups without observations in the additional dataset.

Default: NA_character_


  1. The additional dataset is restricted to the observations matching the filter_add condition.

  2. The categorization variable is added to the additional dataset.

  3. If order is specified, for each by group the first or last observation (depending on mode) is selected.

  4. The categorization variable is merged to the input dataset.


The output dataset contains all observations and variables of the input dataset and additionally the variable specified for new_var derived from the additional dataset (dataset_add).

See Also

Other deprecated: derive_param_extreme_event(), derive_var_basetype(), derive_var_confirmation_flag(), derive_var_last_dose_amt(), derive_var_last_dose_date(), derive_var_last_dose_grp(), derive_var_merged_character(), derive_vars_last_dose()

[Package admiral version 0.12.0 Index]