factorCombinations: Combine Levels of Different Factors to Groups

Description Usage Arguments Value Note Examples

View source: R/LinRegInteractive_functions.R

Description

All levels of the factors from a data.frame provided are combined, each combination of factor levels is referred to as group.

Usage

1
factorCombinations(X, factor.sep = "|", level.sep = ".", count=TRUE)

Arguments

X

A data.frame containing at least one factor.

factor.sep

Character by which the factor-factor level combinations are separated in the group names.

level.sep

Character by which the level names are separated from the corresponding factor names in the group names.

count

Should the occurences of the different groups in the data.frame provided be counted? Default to TRUE.

Value

A list with the following components:

combinations

A data frame containing every combination of factor levels (groups) for the factors provided.

names

A character vector with the names of the groups. Factor-factor level combinations are separated by factor.sep and level names from the corresponding factor names by level.sep.

counts

If count is TRUE a vector indicating the number of occurences of the different groups within the data.frame provided to the function. NULL if count is set to FALSE.

Note

Function is mainly for internal use in LinRegInteractive but may be useful for other purposes as well.

Examples

1
2
3
4
5
6
7
# multiple factors
data("CO2")
print(factorCombinations(CO2))

# single factor
data("chickwts")
print(factorCombinations(chickwts))

LinRegInteractive documentation built on March 26, 2020, 7:26 p.m.