Learn R Programming

gdata (version 2.2.0)

combineLevels: Combine levels of given factors

Description

combineLevels combines levels of given factors and applies this levels to given factors. This eases the work with factors since all factors have the same levels.

Usage

combineLevels(x, apply=TRUE, drop=FALSE)

Arguments

x
data.frame or list, object with factors
apply
boolean, apply combined levels to x or just return combined levels
drop
boolean, drop unused levels

Value

  • apply handles the output. If apply=TRUE the output is a modified x, where all factors have the same set of levels. If apply=FALSE only combined levels are returned.

See Also

factor, levels, mapFactor

Examples

Run this code
(f1 <- factor(letters[1:5]))
(f2 <- factor(letters[3:10]))
tmp <- list(f1, f2)
combineLevels(tmp)
combineLevels(tmp, apply=FALSE)

f1[2] <- NA
f1 <- factor(f1)
tmp <- list(f1, f2)
combineLevels(tmp, apply=FALSE, drop=TRUE)

Run the code above in your browser using DataLab