How to replace NA values with another value in factors in R? I have a factor variable in my data frame with  values where in the original CSV "NA" was intended to mean simply "None", not missing data. Hence I want replace every  value in the given column with "None" factor value. I tried this:

DF$col[is.na(DF$col)] &lt;- "None"


but this throws the following error:

Warning message:
In `[&lt;-.factor`(`*tmp*`, is.na(DF$col), value = c(NA, NA,  :
  invalid factor level, NA generated


I guess this is because originally there is no "None" factor level in the column, but is it the true reason? If so, how could I add a new "None" level to the factor?

(In case you would ask why didn't I convert NAs into "None" in the read.csv phase: in other columns NA really does mean missing data).
You can use this function : 

forcats::fct_explicit_na

library(forcats) 
fct_explicit_na(DF$col, na_level = "None")


Usage

It can be used within the mutate function and piped to edit DF directly: 

library(tidyverse) # for tidy data packages, automatically loads dplyr
library(magrittr) # for piping
DF %&lt;&gt;% mutate(cols = fct_explicit_na(col, na_level = "None"))


Note that "col" needs to be a factor for this to work.