mxFactor {OpenMx}R Documentation

Fail-safe Factors

Description

This is a wrapper for the R function factor. The factor function will skip missing levels 1,2,3,5 if they are not explicitly specified. Use this function to force yourself to write out the levels.

Usage

mxFactor(x = character(), levels, labels = levels, 
	exclude = NA, ordered = TRUE)

Arguments

x either a vector of data or a data.frame object.
levels a mandatory vector of the values that 'x' might have taken.
labels _either_ an optional vector of labels for the levels, _or_ a character string of length 1.
exclude a vector of values to be excluded from the set of levels.
ordered logical flag to determine if the levels should be regarded as ordered (in the order given). Required to be TRUE.

Details

If ‘x’ is a data.frame, then all of the columns of ‘x’ are converted into ordered factors. If ‘x’ is a data.frame, then ‘levels’ and ‘labels’ may be either a list or a vector. When ‘levels’ is a list, then different levels are assigned to different columns of the constructed data.frame object. When ‘levels’ is a vector, then the same levels are assigned to all the columns of the data.frame object. The function will throw an error if ‘ordered’ is not TRUE or if ‘levels’ is missing. See factor for more information on creating ordered factors.

References

The OpenMx User's guide can be found at http://openmx.psyc.virginia.edu/documentation.

Examples


ff <- mxFactor(substring("statistics", 1:10, 1:10), levels=letters)
as.integer(ff)  # the internal codes

factor(ff)      # drops the levels that do not occur.
                # AVOID DOING THIS UNINTENTIONALLY.

foo <- data.frame(x=c(1:3),y=c(4:6),z=c(7:9))
mxFactor(foo, c(1:9)) # same levels applied to all columns
mxFactor(foo, list(c(1:3), c(4:6), c(7:9))) # different levels to different columns

    

[Package OpenMx version 0.3.2-1263 Index]