Skip to content

setattr should handle duplicate 'levels' if factor correctly #1142

@arunsrinivasan

Description

@arunsrinivasan

Compare:

x = factor(rep(1:4, each=2L))
x
# [1] 1 1 2 2 3 3 4 4
# Levels: 1 2 3 4
setattr(x, 'levels', c("a", "a", "b", "b"))
levels(x)
# [1] "a" "a" "b" "b"

with:

x = factor(rep(1:4, each=2L))
x
# [1] 1 1 2 2 3 3 4 4
# Levels: 1 2 3 4

levels(x) = c("a", "a", "b", "b")
levels(x)
# [1] "a" "b"

Reference: Comments section under this post.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions