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).
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, seeclassified.default- persistence
whether to return 'dvec' (is.integer(): TRUE) or just integer.
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
#> [1] 2 1 3
#> attr(,"guide")
#> attr(,"guide")$fork
#> [1] 1
#>
#> attr(,"guide")$knife
#> [1] 2
#>
#> attr(,"guide")$spoon
#> [1] 3
#>
# implement offset
c('knife','fork','spoon') %>% codify(-1)
#> [1] 1 0 2
#> attr(,"guide")
#> attr(,"guide")$fork
#> [1] 0
#>
#> attr(,"guide")$knife
#> [1] 1
#>
#> attr(,"guide")$spoon
#> [1] 2
#>
# globally defeat the 'persistence' paradigm
options(yamlet_persistence = FALSE)
c('knife','fork','spoon') %>%
codify %>%
class # integer
#> [1] "integer"
# remove option to restore default persistence paradigm
options(yamlet_persistence = NULL)
c('knife','fork','spoon') %>%
codify %>%
class # dvec
#> [1] "dvec"
# locally defeat persistence paradigm
c('knife','fork','spoon') %>%
codify(persistence = FALSE) %>%
class # integer
#> [1] "integer"
# pass levels
c('knife','fork','spoon') %>%
codify(levels = c('spoon', 'knife', 'fork'))
#> [1] 2 3 1
#> attr(,"guide")
#> attr(,"guide")$spoon
#> [1] 1
#>
#> attr(,"guide")$knife
#> [1] 2
#>
#> attr(,"guide")$fork
#> [1] 3
#>