Switching "yes" and "no" in a vector for "1" and "2"

Hi

I have a long vector containing nothing but 'yes' or 'no'; I want to code it into 1s and 2s. Please could someone show me how to do it? I've tried using switch and ifelse, but failed.
(Ultimately I want to use the vector in the pch field of my funnel chart, to show two types of points.)

Many thanks!!!!

Annabel

vector_yes_no <- c("yes", "no", "no", "yes", "no")
str(vector_yes_no)
#>  chr [1:5] "yes" "no" "no" "yes" "no"

vector_12 <- ifelse(vector_yes_no == "yes", 1, 2)
str(vector_12)
#>  num [1:5] 1 2 2 1 2
5 Likes

Amazing thanks so much!!!!