Ops.factor
Operations for Factors and Ordered Factors

Description

Defines arithmetic, comparison, and logical operators on factors.

Usage

e1 OP e2
OP e1

Arguments

e1, e2 objects, at least one of which inherits from class "factor", for Ops.factor, or from "ordered" for Ops.ordered.

Details

Each argument of the relevant class is converted to a vector, and the relevant comparison applied to the result. This is a group method for the functions of the Ops group generic, the basic operators for arithmetic, comparison, and logic. It succeeds only for comparison operators. The method fails for arithmetic or logical operators.
Value
returns a logical vector for the comparison operators.
See Also
Methods.
Examples
x <- 1:10
y <- factor(c("top", "bottom", "middle", "top", "bottom", 
   "middle", "top", "middle", "top", "bottom"))
x == y      
x > y   # Warning: '>' is not meaningful for factors

y1 <- ordered(c("top", "bottom", "middle", "top", "bottom", "middle", "top", "middle", "top", "bottom")) y2 <- ordered(c("top", "bottom", "top", "bottom", "middle", "top", "middle", "top", "bottom", "middle" )) y1 >= y2 # TRUE TRUE FALSE TRUE FALSE FALSE TRUE FALSE TRUE FALSE y1 + y2 # Warning: '+' is not meaningful for ordered factors !y1 # Warning: '!' is not meaningful for ordered factors

Package base version 6.1.1-7
Package Index