Convert a variable to a factor with levels in specified order.
convertVarToFactorWithOrder(
data,
var,
otherVars = NULL,
colVar = NULL,
colTotalLab = "Total",
method = c("auto", "alphabetical", "total"),
totalFilterFct = NULL,
totalVar = "statN",
catLast = NULL
)
Factor var
variable of data
with specified order.
Data.frame with dataset to consider for the summary table.
String with variable of data
to sort.
Character vector with other variable(s) of data
considered in the specific dimension.
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.
String, label for the total column 'Total' by default.
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
(optional) Function which returns a subset of the data of interest, to filter the total data considered for the ordering.
String with variable of data
considered in case type
is 'total',
'statN' by default.
String with last category (if any). Set to NULL if no specific category should be included as last element.
Laure Cougnaud