I have a dataframe column populated with strings and NAs, like this:
df <- data.frame(col=as.character(c(NA,'', 'text', '', NA,'text')))
In this case, ' ' and NA both represent NA, and I am trying to standardize so both are NA or so both are ' '. I tried this code:
df$col <- replace_na(df$col, '')
And this code:
df$col <- replace_na(df$col, col = c(''))
But both approaches result in the following output:
Error in UseMethod("replace_na") :
no applicable method for 'replace_na' applied to an object of class "character"
I know this is a common operation and I am sure the solution is simple. What is the syntax for replacing NAs with a string? (Or, what is the best solution to my problem of standardizing the ' ' and NA values?)