fac.uselogical: Forms a two-level 'factor' from a 'logical' object.

fac.uselogicalR Documentation

Forms a two-level factor from a logical object.

Description

Forms a two-level factor from a logical object. It can be used to recode a factor when the resulting factor is to have only two levels.

Usage

fac.uselogical(x, levels = c(TRUE, FALSE), labels = c("yes", "no"), ...)

Arguments

x

A logical vector with values TRUE or FALSE. If the vector is not a logical, as.logical will be used in an attempt to coerce it to logical.

levels

A vector of length two with values TRUE or T and FALSE or F, in either order depending on which of TRUE or FALSE is to be the first level.

labels

A vector of length two with values to be used as labels for the first and second levels, respectively.

...

Further arguments passed to the factor call creating the new factor.

Value

A factor.

Author(s)

Chris Brien

See Also

fac.recast, as.numfac and mpone in package dae, factor, relevel.

Examples

## set up a factor with labels
Treats <- factor(rep(1:4, 4), labels=c("A","B","C","D"))
 
## recode "A" and "D" to "a" and "B" and "C" to "b"
B <- fac.uselogical(Treats %in% c("A", "D"), labels = c("a","b"))
B <- fac.uselogical(Treats %in% c("A", "D"), labels = c(-1,1))

## suppose level A in factor a is a control treatment
## set up a factor Control to discriminate between control and treated
Control <- fac.uselogical(Treats == "A")

dae documentation built on June 22, 2024, 9:07 a.m.