My impression is that factors in R are borderline-deprecated, especially in the tidyverse, in favor of just using the equivalent non-factor vector.
Could you please provide a real world example where this actually is a problem.
Wow. Didn't knew that.. strings is the one thing I always minimize in my datasets, due to speed and memory considerations..
BTW, I wanted to thank you for your 2012 slides on how you used hashes to group and join data. It led me to learn more about categoricals and I ended up implementing a Factor() object [1] in the other tool I use (Stata) that ended up being a life saver. In fact, once you have a powerful and fast categorical type, with a set of key functions, you can do anything from group the data, to count distinct categories, to run fixed effect regressions in no time.
[1] http://fmwww.bc.edu/repec/scon2017/Baltimore17_Correia.pdf
factor(x = character(), levels, labels = levels, exclude = NA, ordered = is.ordered(x), nmax = NA)
[...]
levels
: an optional vector of the values (as character strings) that x might
have taken. The default is the unique set of values taken by
as.character(x), sorted into increasing order of x. Note that this set
can be specified as smaller than sort(unique(x)).
labels
: either an optional character vector of (unique) labels for the
levels (in the same order as levels after removing those in exclude), or
a character string of length 1.
This way, you can do something like that: > x <- 1:3
> factor(x, levels = 1:2, labels = c("foo", "bar"))
[1] foo bar <NA>
Levels: foo bar
But this actually is: > factor(as.character(x), levels = c("1", "2"), labels = c("foo", "bar"))
[1] foo bar <NA>
Levels: foo bar