Discovered a small but important difference between factor() and ordered() in #Rstats -- only took about an hour of debugging🤦
2
3
9
Replying to @jamesotto852
Seems like a bug because this does seems to do what you want as well: > factor(levels=c("a", "b", "c"), ordered=TRUE) ordered(0) Levels: a < b < c >

Aug 18, 2022 · 2:55 PM UTC

1
3
Replying to @eddelbuettel
Yes, that also works! It might be a bug, the issue stems from the defaults. The first argument of both functions is x. In factor(), its default is character(). But, in ordered() it has no default value. So it errors unless you explicitly set x = character().
1