0

I have a character vector comprising:

male, maLe, Male, MALE, ma8le characters. I want to replace the above with "Male" How to do this in R

I tried 'sub', 'gsub', 'str_replace'. The solution must be Similar to python given below:

df['gender'].replace(["male", "maLe", "Male", "MALE", "ma8le"], ["Male","Male","Male","Male","Male"], inplace = True)

I need to perform the same in R

gend_cor<- c("male", "maLe", "Male", "MALE", "ma8le")

data$gender <- gsub(gend_cor, "Male", data$gender)

My expected output is If I enter the above "gend_cor", it must return Male instead of the other wrong words

Sotos
  • 51,121
  • 6
  • 32
  • 66
Ravi
  • 187
  • 1
  • 1
  • 7

0 Answers0