convertVarToFactorWithOrder: Convert a variable to a factor with levels in specified...

View source: R/computeSummaryStatisticsTable.R

convertVarToFactorWithOrderR Documentation

Convert a variable to a factor with levels in specified order.

Description

Convert a variable to a factor with levels in specified order.

Usage

convertVarToFactorWithOrder(
  data,
  var,
  otherVars = NULL,
  colVar = NULL,
  colTotalLab = "Total",
  method = c("auto", "alphabetical", "total"),
  totalFilterFct = NULL,
  totalVar = "statN",
  catLast = NULL
)

Arguments

data

Data.frame with dataset to consider for the summary table.

var

String with variable of data to sort.

otherVars

Character vector with other variable(s) of data considered in the specific dimension.

colVar

Character vector with variable(s) to be included in columns. If multiple variables are specified, the variables should be sorted in hierarchical order, and are included in multi-columns layout.
Use: 'variable' to include the variables to summarize: var (if multiple) in different columns.

colTotalLab

String, label for the total column 'Total' by default.

method

Ordering method to use, either:

  • String among:

    • 'auto': if var is a factor, keep its order, otherwise alphabetically

    • 'alphabetical': var is order in alphabetical order

    • 'total': var is ordered based on the totalVar variable, in decreasing order. The total count is extracted from the rows with all otherVars equal to 'Total'. If no otherVars is specified, consider all rows.

  • Function to be applied on each subset to get the order elements of the variable

totalFilterFct

(optional) Function which returns a subset of the data of interest, to filter the total data considered for the ordering.

totalVar

String with variable of data considered in case type is 'total', 'statN' by default.

catLast

String with last category (if any). Set to NULL if no specific category should be included as last element.

Value

Factor var variable of data with specified order.

Author(s)

Laure Cougnaud


inTextSummaryTable documentation built on Sept. 12, 2023, 5:06 p.m.