Next: makestr() Up: MacAnova Help File Previous: makecols()   Contents

makefactor()

Usage:
makefactor(vec [,sort:F] [,labels:T or F]), vec a REAL, CHARACTER or
  LOGICAL vector



Keywords: glm, anova, character variables
makefactor(vec) creates a factor constructed from the REAL, CHARACTER or
LOGICAL vector vec.  If there are m unique values in vec, the output
will be a factor with m levels in the same order as the values in vec.
MISSING values remain MISSING.

makefactor(vec, sort:F) does the same, except the factor levels may not
have the same order as the elements of vec.  Level 1 will be assigned to
value[1], level 2 to the next value in vec different from vec[1], and so
on.

If vec is a CHARACTER vector without row labels, its values are attached
to the result as row labels unless 'labels:F' is an additional argument.

If vec has row labels, they become the row labels of the result.

makefactor(vec, labels:F, [, sort:F]) does the same, except the result
has no row labels.

makefactor(vec, labels:T, [, sort:F]) does the same, except that if vec
does not have labels, a CHARACTER representation of the values in vec is
attached to the result as row labels.

Even when vec is REAL and consists of positive integers, it may be
preferable to use makefactor() rather than factor(), since the output
from factor() will not contain all m levels if max(vec) > m, or if some
levels are missing in vec.

Examples:
  Cmd> a <- makefactor(vector(5.2,2.6,3.9,1.3,3.9,1.3,5.2,2.6)); a
  (1)           4           2           3           1           3
  (6)           1           4           2

  Cmd> b <- makefactor(vector("D","B","C","A","C","A","D","B"));b
           D           B           C           A           C
           A           D           B
           4           2           3           1           3
           1           4           2

  Cmd> c <- makefactor(vector(5.2,2.6,3.9,1.3,3.9,1.3,5.2,2.6),sort:F);c
  (1)            1            2            3            4            3
  (6)            4            1            2

  Cmd> d <- makefactor(rpoi(5,11)/10,labels:T); d
           1.2         0.9           1         1.4         0.9
             3           1           2           4           1

makefactor() is implemented as a macro.

See also factor().


Gary Oehlert 2003-01-15