Matching a pattern with `match()` with extra condition
问题 Expanding on a previous question (R: gsub of exact full string with fixed = T). [With huge thanks to everyone who helped there. Special thanks to @MrFlick] I need to change "32 oz" to "32 ct" but only if extra condition "3" is met, not in any other case. exact_orig = c("oz" ,"32 oz") exact_change = c("20 oz","32 ct") exact_flag = c("1" ,"3") fixedTrue<-function(x,y) { m <- match(x, exact_orig) n <- match(y, exact_flag) x[!is.na(m) & n[!is.na(n)]]<- exact_change[m[!is.na(m)] & n[!is.na(n)]] x