as.vector.factor
Coerce a Factor Object into a Vector of a Given Mode

Description

This method implements the as.vector generic funcion for factor objects. It returns a vector that is the result of applying the appropriate as.* function to the argument. See the description of the mode argument for a list of supported storage modes.

Usage

as.vector.factor(x, mode = "any")

Arguments

x a factor object.
mode the result mode. It supports the following:
  • list
  • integer
  • double
  • numeric (equivalent to double)
  • complex
  • character, any (equivalent to character), logical, and expression.
Any other mode generates an error.
Value
a vector of the specified mode.
Examples
x <- factor(c("R", "G", "B", "R"))
as.vector.factor(x, mode = "any")
# [1] "R" "G" "B" "R"
as.vector.factor(x, mode = "list")
# [[1]]
# [1] R
# Levels: B G R

# [[2]] # [1] G # Levels: B G R

# [[3]] # [1] B # Levels: B G R

# [[4]] # [1] R # Levels: B G R

as.vector.factor(x, mode = "integer") # [1] 3 2 1 3 as.vector.factor(x, mode = "double") # [1] 3 2 1 3 as.vector.factor(x, mode = "numeric") # [1] 3 2 1 3 as.vector.factor(x, mode = "complex") # [1] 3+0i 2+0i 1+0i 3+0i as.vector.factor(x, mode = "logical") # [1] NA NA NA NA as.vector.factor(x, mode = "character") # [1] "R" "G" "B" "R" as.vector.factor(x, mode = "expression") # expression(3L, 2L, 1L, 3L) ## Not run: as.vector.factor(x, mode = "foo") ## Error in as.vector(x, mode) : invalid 'mode' argument ## End(Not run)

Package base version 6.1.1-7
Package Index