nom2dum converts a nominal variable into a set of dummy variables.
There is one dummy variable for each unique value in the nominal variable.
Note, base R does this recoding internally through the
model.matrix.default function, but it is used in the context of
regression-like models and it is not clear how to simplify it for general use
cases outside that context.
character vector (or any atomic vector, including factors, which will be then coerced to a character vector) specifying the nominal variable.
atomic vector of length 1 specifying what unique value should represent rows when the nominal category of interest is present. For a traditional dummy variable this value would be 1.
atomic vector of length 1 specifying what unique value should represent rows when the nominal category of interest is absent. For a traditional dummy variable this value would be 0.
character vector of length 1 specifying the string that should be appended to the beginning of each colname in the return object.
logical vector of length 1 specifying whether the columns of
the return object should be factors where the first level is
no are assumed to be the same typeof. If
they are not, then the columns in the return object will be coerced to the
most complex typeof (i.e., most to least: character, double, integer,
data.frame of dummy columns with colnames specified by
paste0(prefix, unique(nom)) and rownames specified by
names(nom) or default
data.frame rownames (i.e.,
c("1","2","3", etc.) if
1 2 3 4
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.