Creates a factor of subclass 'classified',
for which there are attribute-preserving methods.
In particular, classified has a codelist attribute
indicating the origin of its levels: it is
constructed from the codelist attribute of x
if available, or from 'levels' and 'labels'
by default. Unlike the case for factor,
length of labels cannot be one (i.e., different from
length of levels).
Usage
# Default S3 method
classified(
x = character(),
levels,
labels,
exclude = NA,
ordered = is.ordered(x),
nmax = NA,
token = character(0),
...
)See also
Other classified:
[.classified(),
[<-.classified(),
[[.classified(),
[[<-.classified(),
as.integer.classified(),
c.classified(),
classified(),
classified.classified(),
classified.data.frame(),
classified.dvec(),
classified.factor(),
codify.default(),
desolve.classified(),
unclassified(),
unclassified.classified(),
unclassified.data.frame()
Examples
# classified creates a factor with a corresponding codelist attribute
classified(c('a','b','c'))
#> [1] a b c
#> attr(,"codelist")
#> attr(,"codelist")[[1]]
#> [1] a
#>
#> attr(,"codelist")[[2]]
#> [1] b
#>
#> attr(,"codelist")[[3]]
#> [1] c
#>
#> Levels: a b c
# codelist 'remembers' the origins of levels
classified(c('a','b','c'), labels = c('A','B','C'))
#> [1] A B C
#> attr(,"codelist")
#> attr(,"codelist")$a
#> [1] A
#>
#> attr(,"codelist")$b
#> [1] B
#>
#> attr(,"codelist")$c
#> [1] C
#>
#> Levels: A B C
# classified is 'reversible'
library(magrittr)
c('a','b','c') %>%
classified(labels = c('A','B','C')) %>%
unclassified
#> [1] "a" "b" "c"
#> attr(,"codelist")
#> attr(,"codelist")$A
#> [1] "a"
#>
#> attr(,"codelist")$B
#> [1] "b"
#>
#> attr(,"codelist")$C
#> [1] "c"
#>