Math.factor
Math Group Method for Factor Objects

Description

Generates an error if a Math Group function is called on a factor or ordered factor.

Usage

Math.factor(x, ...)

Arguments

x any object that inherits from class "factor"
... not used in this method.

Details

This method is called whenever any of the Math Group functions is called on a factor or ordered factor. It generates an error "<function name> not meaningful for factors", because all the Math Group functions require a numerical object as an argument. This method exists in order to prevent the Math Group functions from automatically converting factors or ordered factors to numeric objects.
Explicitly call as.integer on a factor if you want to use the numeric representation of the equivalence relation defined by the factor.
See Also
factor, Math, as.integer
Examples
color <- c("pink", "red", "green", "red", "red", "blue")
colors <- factor(color, c("red", "green", "blue"))
sin(colors)
# Error in Math.factor(colors) : sin not meaningful for factors

as.integer(colors) # [1] NA 1 2 1 1 3

sin(as.integer(colors)) # [1] NA 0.8414710 0.9092974 0.8414710 0.8414710 0.1411200

Package base version 6.0.0-69
Package Index