Question: I have two maps, how will I be able to delete the entries in map 1 whose keys aren't present in map b? (The values don't matter). Here's what I've tried so far, but when I return map 1, the "excessobject" key is still being returned.

```
const map1 = new Map () 
map1.set = (object1, 1) 
map1.set = (object2, 2) 
map1.set = (excessobject, 3) 

const map2 = new Map ()
map2.set = (object1, 1) 
map2.set = (object2, 2) 

for (const key of map1.keys()) 
  map1.delete(!map2.has(key))

map1; 

```

Answer: 
We can use `coalesce`. Loop over the 'var' columns and use `coalesce` with the looped column and 'ref', so that wherever there is `NA`, it gets replaced by the corresponding element from 'ref', while the other non-NA element remain as such

```
library(dplyr) #>= 1.0.0
df %>% 
     mutate(across(starts_with('var'), ~ coalesce(., ref)))
#   ref var1 var2
#1   1    1    1
#2   3    3    3
#3   4    4    4
#4   2    2    5
#5   5    1    5

```
This can also works:

```
library(dplyr)

df %>%
  mutate(across(c(var1:var2),~ ifelse(is.na(.), ref, .)))

```

Output:

```
  ref var1 var2
1   1    1    1
2   3    3    3
3   4    4    4
4   2    2    5
5   5    1    5

```