a vector giving the numeric values to be assigned to the levels of
x. If numeric levels are not specified and levels(x) can be
coerced to numeric values, these values are used levels. If numeric
levels are not specified, levels(x) cannot be coerced to numeric and
coerce is T the values 1:length(levels(x)) are used. Otherwise an
error is generated.
coerce:
logical value for whether to coerce non-numeric levels to integers.
VALUE:
A numeric vector, with the factor levels replaced by numeric values.
WARNING:
The numeric levels are matched with the order of levels(x). The
order of levels(x) determined internally by S-PLUS (typically as
sort(unique(x)), and may not
correspond to the order of appearance in the factor. For example, a
factor with the levels "-" and "+", has levels(x) of c("+","-"). The
numeric levels must be supplied in the corresponding order. However, if the
factor is an ordered factor, with "-" < "+", this order is preserved
by S-PLUS. See the example below.
EXAMPLES:
f <- factor(rep(c("+","0","-"), 5))
ff <- ordered(rep(c("+","0","-"), 5), c("-","0","+"))
fac2num(f)
fac2num(ff)
fac2num(f, num = c( -5, 0, 5))
fac2num(ff, num = c( -5, 0, 5))