as.integer.classified | R Documentation |
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.
## S3 method for class 'classified'
as.integer(
x,
offset = 0L,
...,
persistence = getOption("yamlet_persistence", TRUE)
)
x |
classified, see |
offset |
an integer value to add to intermediate result |
... |
passed to |
persistence |
whether to return 'dvec' (is.integer(): TRUE) or just integer. |
integer (possibly of class dvec)
Other classified:
[.classified()
,
[<-.classified()
,
[[.classified()
,
[[<-.classified()
,
c.classified()
,
classified()
,
classified.classified()
,
classified.data.frame()
,
classified.default()
,
classified.dvec()
,
classified.factor()
,
desolve.classified()
,
unclassified()
,
unclassified.classified()
,
unclassified.data.frame()
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.