I am searching for the formula to change a 'NA' value with a value such as 'Y' within a column of a dataset.
Assuming your column is called
col1 and your dataset is
df, you can do this:
# Replace NAs with "Y", otherwise keep it as the existing value df <- df %>% mutate(col1 = ifelse(is.na(col1) == TRUE, "Y", col1))
Another way is with the function
library(tidyverse) # this replaces all values of NA with a "Y" df %>% replace_na("Y") # this replaces all values of NA with a "Y" for variable col1 df %>% replace_na(list(col1="Y"))
Thanks very much. The code worked just fine..
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.