codify.default: Convert to Codes by Default

View source: R/classified.R

codify.defaultR Documentation

Convert to Codes by Default

Description

Reduces x integer codes with appropriate decorations. Result is like as.integer(as.numeric(x)) + offset but has a guide attribute: a list of integers whose names are the original levels of x. A wrapper for as.integer(classified(x).

Usage

## Default S3 method:
codify(
  x,
  offset = 0L,
  ...,
  persistence = getOption("yamlet_persistence", TRUE)
)

Arguments

x

anything for which there is a 'classified' method; see classified

offset

an integer value to add to intermediate result

...

passed to classified; for relevance, see classified.default

persistence

whether to return 'dvec' (is.integer(): TRUE) or just integer.

Value

integer (possibly of class dvec)

See Also

as.integer.classified mimic

Other classified: [.classified(), [<-.classified(), [[.classified(), [[<-.classified(), as.integer.classified(), c.classified(), classified(), classified.classified(), classified.data.frame(), classified.default(), classified.dvec(), classified.factor(), desolve.classified(), unclassified(), unclassified.classified(), unclassified.data.frame()

Examples

library(magrittr)

# convert to decorated integer
c('knife','fork','spoon') %>% codify

# implement offset
c('knife','fork','spoon') %>% codify(-1)

# globally defeat the 'persistence' paradigm
options(yamlet_persistence = FALSE)
c('knife','fork','spoon') %>% 
  codify %>% 
  class # integer
  
# remove option to restore default persistence paradigm
options(yamlet_persistence = NULL)
c('knife','fork','spoon') %>% 
  codify %>%
  class # dvec
  
# locally defeat persistence paradigm
c('knife','fork','spoon') %>% 
  codify(persistence = FALSE) %>% 
  class # integer
  
# pass levels
c('knife','fork','spoon') %>%
  codify(levels = c('spoon', 'knife', 'fork'))


yamlet documentation built on Oct. 25, 2026, 1:07 a.m.