I have a string variable in a large data set that I want to cleanse based on a set list of strings. ex. pattern <- c("dog","cat") but my list will be about 400 elements long.

**vector\_to\_clean == a**

```
black Dog
white dOG
doggie
black CAT
thatdamcat

```

Then I want to apply a function to yield

**new**

```
dog
dog
dog
cat
cat

```

I have tried str\_extract, grep, grepl etc.. Since I can pick a pattern based on one string at a time. I think what I want is to use dapply with one of these text cleansing functions. Unfortunately, I'm stuck. Below is my latest attempt. Thank you for your help!

```
new <- vector()

lapply(pattern, function(x){
  where<- grep(x,a,value = FALSE, ignore.case = TRUE)
  new[where]<-x
  })

```