I have a data frame that contains missing values. These missing values span multiple variables but arise in said variables, all at once, on specific observations. For example, my data frame looks something like:

```
r1 = c('', 'abc def', '')
r2 = c('1', 'ghi jkl', '2')
r3 = c('', 'mno pqr', '')
df = as.data.frame(rbind(r1, r2, r3))

```

I would like to fill both missing values with "x" in all cases where df$V2 contains 'def', fill both missing values with "y" in all cases where df$V2 contains 'pqr', and leave alone all rows for which df$V2 contains 'jkl'. In other words, I'd like to end up with a data frame that looks like:

```
    V1  V2      V3
r1  x   abc def     x
r2  1   ghi jkl     2
r3  y   mno pqr     y

```

Can I write a function to conditionally fill empty cells in multiple columns of a single row based on a subset of the text of a character variable in that row? Your help is much appreciated.