get_reduce_fn: Get Combiner Function

View source: R/instance_array_helper.R

get_reduce_fnR Documentation

Get Combiner Function

Description

Helper to define a reduction function for combining instances and arrays. Returns a binary function based on the specified options. Typically used by instance_combiner() and reduce_by_row().

Usage

get_reduce_fn(
  combine_instances = c("any", "max", "min", "first", "last", "mean")
)

Arguments

combine_instances

The method used by instance_combiner() or other Reduce-like functions when combining results of a lookup (e.g. a medication lookup, icd10 lookup, biomarker lookup) across multiple instances.

For example, when looking up whether a participant is on a medication, the result may differ depending on the instance number. In such a case, one would want to apply the "any" method so that results for instance 2 will be Reduce()-ed with the or operator applied to the results of instances 0 and 1. In the case of numeric lookups (e.g. biomarkers that are recorded at multiple instances), one might want to use the "mean" method to average results across instances.

Can be one of:

  • "any" - use Boolean or (note: requires that lookup results are logical)

  • "min" - use the minimum non-NA value

  • "max" - use the maximum non-NA value

  • "first" - use the first/earliest non-NA value

  • "last" - use the last/latest non-NA value

  • "mean" - use the mean of non-NA values

Functions that call combine_instances() may restrict the choice of options (e.g. it doesn't make sense to apply "any" to numeric data).


adamleejohnson/R-ukbiobank documentation built on April 25, 2022, 2:11 a.m.