Replacing Values ​​with Variables


I have data in R schools which has 94 variables. Out of which I selected 3 variables in a set for analysis:

schools_set <- data.frame(schools$Schoolname, schools$SchoolGenderID, and School$)

The SchoolGenderID is sorted columnwise (1s and 2s) 1 for male and 2 for female. My question is, how can I replace these 1s and 2s with "Male" and "Female" respectively in the variable schools$SchoolGenderID within the same data frame?

schools$SchoolGenderID[schools$SchoolGenderID == 1] <- "Male"
schools$SchoolGenderID[schools$SchoolGenderID == 2] <- "Female"


schools$SchoolGenderID <- ifelse(schools$SchoolGenderID == 1, "Male", "Female")

Recommending the latter in this particular situation.