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.
Compare:
with:
Reference: Comments section under this post.