replace Yes, No to 1, 0 in multiple columns in r [duplicate]
问题 This question already has answers here : Converting Yes and No to 0 and 1 in R (3 answers) Closed last year . I need to replace the Yes and No values to 1 and 0 in 200 columns. I was using with the command data %>% mutate(x=ifelse(x=="Yes", 1,0)) but i have to go through each column at a time, and i was wondering if there was any way i could do it all at once. 回答1: You may use ifelse on the entire data frame: df <- data.frame(v1=c("Yes","No"), v2=c("No","Yes"), stringsAsFactors=FALSE) ifelse