Learn R Programming

jwutil (version 1.1.1)

expandFactors: Takes factors from a data frame and converts them to true/false fields with appropriately named fields.

Description

For a two level factor, this is relatively easy, since we just replace the field with x==levels(x)[1] or something like that, and rename the field to indicate that TRUE is level 1 of the factor. This works well for gender. For multi-level factors there is redundancy with multiple new fields now containing FALSE, with only one TRUE for the matching level.

Usage

expandFactors(x, consider = names(x), sep = "", na.rm = TRUE,
  verbose = FALSE)

Arguments

x

data.frame to search for factors to convert

consider

character vector of field names in the data frame to consider. Defaults to all fields

sep

character scalar used to separate field prefixes from factor values in new column names

na.rm

logical scalar: if NA data and/or NA levels, then covert to NA strings and expand these as for any other factor

verbose

single logical value, if TRUE then produce verbose messages

Value

data.frame with no factors

See Also

PSAgraphics::cv.trans.psa