I just stumbled upon a strange conversion aspect of the c()
function's treatment of factors in R 3.3.1. Here is a basic example:
> x <- factor(c("X", "X", "Y", "Y", "X"))
> x[2] <- NA
> x
[1] X <NA> Y Y X
Levels: X Y
all good. but how do I push an <NA>
onto x now? the problem is that the c() function seems to convert factors into integers, so
> c(x, NA)
> c(x,NA)
[1] 1 NA 2 2 1 NA
> c(x)
[1] 1 1 2 2 1
this seems odd. logically, the c() function should not convert factors to integers when not necessary. (curious: is there a good reason?) is there a c() function for factors?