dropCoarseLevels: Remove Coarse Levels from a Coarsened Factor

View source: R/coarsened.R

dropCoarseLevelsR Documentation

Remove Coarse Levels from a Coarsened Factor

Description

A coarsened factor, produced by the function coarsened, has two types of levels: base levels, to represent observations that are fully known, and coarse levels, to represent observations that are partially or completely missing. The function dropCoarseLevels converts a coarsened factor to a factor or ordered factor by removing all of the coarse levels and setting the corresponding observations to NA.

Usage

dropCoarseLevels(x)

Arguments

x

a factor or coarsened factor

Details

If the only coarse level of x is NA, then no information is lost when dropCoarseLevels is applied. If x has other non-empty coarse levels, then the partial information carried by those observations is effectively discarded.

Value

A factor or ordered factor, obtained by removing the coarse levels of x and setting the observations in those levels to NA.

If x is a factor but not a coarsened factor, then it is returned unchanged.

Author(s)

Joe Schafer Joseph.L.Schafer@census.gov

References

For more information about coarsened factors in the cvam package, see the vignette Understanding Coarsened Factors in cvam.

See Also

cvam, coarsened, baseLevels, is.naCoarsened

Examples

fac <- factor( c("red", "green", NA, "yellow", "notRed", "green") )
cFac <- coarsened( fac,
   levelsList = list("notRed" = c("green", "yellow")) )
dropCoarseLevels(cFac)

cvam documentation built on March 7, 2023, 5:29 p.m.