Create or Modify Ordered Factors

DESCRIPTION:
Returns an object of class "ordered" which is an ordered category.

USAGE:
ordered(x, levels=<<see below>>, labels=<<see below>>, exclude=NA)
ordered(x) <- levels
is.ordered(x)
as.ordered(x)

REQUIRED ARGUMENTS:
x:
data to be made into an ordered factor.

OPTIONAL ARGUMENTS:
levels:
vector of levels for the factor. Any data value that does not match a value in levels is coded in the output vector as NA. The levels will be assumed ordered (low to high) in the order given. If omitted, the sorted unique values of x will be used. Note that the sort function removes numeric NA's before sorting, so the default levels for numeric data will not include any NAs. If x is character data or you wish to exclude other values from the levels you may use the exclude argument.
labels:
vector of values to use as labels for the levels of the factor. The default is as.character(levels).
exclude:
a vector of values to be excluded from forming levels. Any value that appears in both x and exclude will be NA in the result and it will not appear in the default levels attribute.


VALUE:
ordered returns an ordered factor, i.e., an object of class c("ordered", "factor").

is.ordered returns TRUE if x inherits from class "ordered", and FALSE otherwise.

as.ordered returns x if x inherits from class "ordered", and returns ordered(x) otherwise.


SIDE EFFECTS:
when ordered is used on the left of an assignment, the levels of x will be taken to be ordered according to the argument on the right side of the assignment. Typically, levels in this case will consist of some permutation of the current levels of x. If values in levels(x) are missing from levels, any corresponding data values in x will become NA.

DETAILS:
The assignment can also be applied to a data frame, in which case the right side is taken to apply to each of the variables in the data frame. The right side should be either a logical vector of length equal to the number of variables, or else a list of the same length. In the case of a list, each element acts like the right side of an assignment of the ordered attribute of the corresponding variable.

The assignment version of the function, "ordered<-" is generic. There is a method for data frames as well as a default method.


SEE ALSO:
factor , levels , codes , design , data.frame .

EXAMPLES:
ratings <- ordered(ratings.text, c("Low","Med","High") )
# reverse the ordering
ordered(ratings) <- c("High","Med","Low")

temperature <- ordered(c(140, 140, 125, 125, 130, 130)) as.vector(temperature, "numeric") # coerce to numeric codes(temperature) # numeric vector of indices in to the levels