With replace
, the lengths should be the same, so we need to subset the Other
as well with the logical expression
data %>%
mutate(X25 = replace(X25, X25 == "Other", Other[X25=="Other"]))
Another option would be case_when
data %>%
mutate(X25 = case_when(X25=="Other"~ Other,
TRUE ~ X25))
Or ifelse
data %>%
mutate(X25 = ifelse(X25 == "Other", Other, X25))