as.integer.classified {yamlet}R Documentation

Coerce Classified to Integer

Description

Coerces classified to integer. 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. If you need a simple integer, consider coercing first to numeric.

Usage

## S3 method for class 'classified'
as.integer(
  x,
  offset = 0L,
  ...,
  persistence = getOption("yamlet_persistence", TRUE)
)

Arguments

x

classified, see classified

offset

an integer value to add to intermediate result

...

passed to desolve

persistence

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

Value

integer (possibly of class dvec)

See Also

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

Examples

library(magrittr)

# create factor with codelist attribute
classified(c('knife','fork','spoon'))

# give back a simple numeric
classified(c('knife','fork','spoon')) %>% as.numeric

# intentionally preserve levels as 'guide' attribute
classified(c('knife','fork','spoon')) %>% as.integer

# implement offset
classified(c('knife','fork','spoon')) %>% as.integer(-1)

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


[Package yamlet version 1.0.3 Index]