See classified.default.
Formerly (version 0.10.10), calling classified() on a
classified object was a non-operation.
Currently we call factor(x, ...) and then
try to reconcile the codelist attribute with resulting
levels.
Usage
# S3 method for class 'classified'
classified(
x,
levels,
labels,
exclude = NULL,
ordered = is.ordered(x),
nmax = NA,
drop = FALSE,
...
)Arguments
- x
classified
- levels
passed to
factor; defaults tolevels(x)- labels
passed to
factor; must be same length as levels(after removing values inexcludeand unused levels ifdropis TRUE) and must not contain duplicates- exclude
passed to
factor- ordered
passed to
factor- nmax
passed to
factor- drop
whether to drop unused levels
- ...
ignored
Details
By default classified is idempotent, such that classified(classified(x)) is the same as classified(x). In contrast, factor(factor(x)) will drop unused levels (not shown). To drop unused levels, use classified(classified(x), drop = TRUE).
See also
Other classified:
[.classified(),
[<-.classified(),
[[.classified(),
[[<-.classified(),
as.integer.classified(),
c.classified(),
classified(),
classified.data.frame(),
classified.default(),
classified.dvec(),
classified.factor(),
codify.default(),
desolve.classified(),
unclassified(),
unclassified.classified(),
unclassified.data.frame()
Examples
a <- 4:6
attr(a, 'codelist') <- list(d = 4, e = 5, f = 6, g = 7)
b <- classified(a)
a
#> [1] 4 5 6
#> attr(,"codelist")
#> attr(,"codelist")$d
#> [1] 4
#>
#> attr(,"codelist")$e
#> [1] 5
#>
#> attr(,"codelist")$f
#> [1] 6
#>
#> attr(,"codelist")$g
#> [1] 7
#>
b
#> [1] d e f
#> attr(,"codelist")
#> attr(,"codelist")$`4`
#> [1] d
#>
#> attr(,"codelist")$`5`
#> [1] e
#>
#> attr(,"codelist")$`6`
#> [1] f
#>
#> attr(,"codelist")$`7`
#> [1] g
#>
#> Levels: d e f g
class(b)
#> [1] "classified" "factor"
classified(b)
#> [1] d e f
#> attr(,"codelist")
#> attr(,"codelist")$`4`
#> [1] d
#>
#> attr(,"codelist")$`5`
#> [1] e
#>
#> attr(,"codelist")$`6`
#> [1] f
#>
#> attr(,"codelist")$`7`
#> [1] g
#>
#> Levels: d e f g
identical(b, classified(b))
#> [1] TRUE