recode is probably the most straightforward approach for your case, but the code below shows a few options. I've converted to numeric, rather than character/factor. Did you want the new 1 and 2 values to be coded as factor? If so, it would make more sense to keep the original coding for sex and just convert that to factor class.
library(tidyverse)
# Fake data
set.seed(2)
d = data.frame(sex = sample(c("Male","Female"), 10, replace=TRUE))
d$sex[5] = NA
d
#> sex
#> 1 Male
#> 2 Male
#> 3 Female
#> 4 Female
#> 5 <NA>
#> 6 Female
#> 7 Male
#> 8 Male
#> 9 Male
#> 10 Female
sexObserved = recode(d$sex, "Male"=1, "Female"=2, .missing=4)
sexObserved
#> [1] 1 1 2 2 4 2 1 1 1 2
sexObserved = ifelse(d$sex=="Male", 1, 2)
sexObserved
#> [1] 1 1 2 2 NA 2 1 1 1 2
sexObserved = case_when(d$sex=="Male" ~ 1,
d$sex=="Female" ~ 2,
is.na(d$sex) ~ 4,
TRUE ~ 3)
sexObserved
#> [1] 1 1 2 2 4 2 1 1 1 2
Created on 2021-02-24 by the reprex package (v1.0.0)