dt.median.numerics {DTwrappers2}R Documentation

dt.median.numerics

Description

wrapper function that computes the median value for each selected quantitative variable in each group after applying a filter.

Usage

dt.median.numerics(
  dt.name,
  the.variables = ".",
  the.filter = NULL,
  grouping.variables = NULL,
  sortby.group = TRUE,
  table.format = "wide",
  add.function.name = FALSE,
  return.as = "result",
  envir = parent.frame(),
  na.rm = TRUE,
  non.numeric.value = "missing",
  ...
)

Arguments

dt.name

a character value specifying the name of a data.frame or data.table object.

the.variables

a character vector specifying the variables that we want to apply a function to. Only values that exist in names(dat) will be used; other values in the.variables will be excluded from the calculation. When the.variables includes ".", then all values in names(dat) will be selected. Values of the.variables that also exist in grouping.variables will be excluded from the.variables (but grouped by these values).

the.filter

a character value, logical value, or expression stating the logical operations to be performed in filtering the data prior to calculating the.function.

grouping.variables

a character vector specifying variables to group by in performing the computation. Only values that exist in names(dat) will be used.

sortby.group

a logical value to specify if the sorting functionality needs to be applied or not

table.format

a character vector specifying if table should be in a wide format or a tall format

add.function.name

a logical value specifying whether the name of the function applied should be appended to the column names in the resulting table.

return.as

describes whether return should be result, code or mixture of both

envir

the environment in which the code would be evaluated; parent.frame() by default.

na.rm

a logical value specifying whether missing values should be removed from the calculations specified by the.functions.

non.numeric.value

if "missing", returns NA for variables that are not numeric, integer, logical, or complex. Otherwise returns first entry of the vector.

...

additional arguments to be passed

Value

The function returns an output based on the 'return.as' parameter: - If 'return.as' is "result", it provides a modified version of the input data frame or data table, showing the median values for the specified numeric variables, after applying the set filters and groupings. The data is presented in the format specified by 'table.format', either wide or tall, and it reflects any sorting by group as dictated by 'sortby.group'. - If 'return.as' is "code", the function will return the R code or expressions that would generate the calculated medians, offering users the opportunity to inspect or execute the code separately. - If 'return.as' incorporates other options, the output may consist of both the calculated medians and the R code, varying according to the function’s implementation.

The function aims to aggregate median values, taking into account the handling of missing values as specified by 'na.rm' and adapting for non-numeric values as determined by 'non.numeric.value'. This functionality allows for a nuanced analysis of the central tendency within the dataset, particularly after subgrouping and applying specified filters.


[Package DTwrappers2 version 0.0.2 Index]