I have a column in my dataset that is a of factor values. Here is an example dataset:
a <- c(1,4,6,3,8)
b <- c("No","Yes","NA", "Maybe", "Yes")
df <- data.frame(a,b)
I'd like to change the NA in column 2 ("b") to "Sometimes". I have tried two different approaches that, in my mind, should work but don't seem to give me the correct output:
df[is.na(df$b)] <- "Sometimes"
df[df$b == "NA"] <- "Sometimes"
Is there a way to do this?