How can I keep NA when I change levels
问题 I build a vector of factors containing NA. my_vec <- factor(c(NA,"a","b"),exclude=NULL) levels(my_vec) # [1] "a" "b" NA I change one of those levels. levels(my_vec)[levels(my_vec) == "b"] <- "c" NA disappears. levels(my_vec) # [1] "a" "c" How can I keep it ? EDIT @rawr gave a nice solution that can work most of the time, it works for my previous specific example, but not for the one I'll show below @Hack-R had a pragmatic option using addNA, I could make it work with that but I'd rather a