Learn R Programming

cvam (version 0.9.3)

dropCoarseLevels: 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)

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.

Arguments

x

a factor or coarsened factor

Author

Joe Schafer Joseph.L.Schafer@census.gov

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.

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

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

Run the code above in your browser using DataLab