I have a variable q with various levels. Some of the levels are actually the same but have been bad reported.
length(q) [1] 13490 > levels(q) [1] \"
One solution could be to use grep and/or grepl:
grep
grepl
x <- c("toto", "CERACETT","CERASETTE","Cerazette","CERAZETTE","CEVAZETTE", "youpi") grep("ce[vr]a[z]ett[e]", x, ignore.case = TRUE, value = TRUE) x[grepl("ce[vr]a[sz]ett[e]", x, ignore.case = TRUE)] <- "replacement_string"