Learn R Programming

LinRegInteractive (version 0.3-4)

factorCombinations: Combine Levels of Different Factors to Groups

Description

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

Usage

factorCombinations(X, factor.sep = "|", level.sep = ".", count=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.

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.

Examples

Run this code
# multiple factors
data("CO2")
print(factorCombinations(CO2))

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

Run the code above in your browser using DataLab