Exercise

# Detecting convergence

Great job iterating over the variables in the last exercise! But how many iterations are needed? When the imputed values don't change with the new iteration, we can stop.

You will now extend your code to compute the differences between the imputed variables in subsequent iterations. To do this, you will use the Mean Absolute Percentage Change function, defined for you as follows:

```
mapc <- function(a, b) {
mean(abs(b - a) / a, na.rm = TRUE)
}
```

`mapc()`

outputs a single number that tells you how much `b`

differs from `a`

. You will use it to check how much the imputed variables change across iterations. Based on this, you will decide how many of them are needed!

The boolean masks `missing_air_temp`

and `missing_humidity`

are available for you, as is the hotdeck-initialized `tao_imp`

data.

Instructions 1/3

**undefined XP**

- Create two empty vectors called
`diff_air_temp`

and`diff_humidity`

for storing differences in the corresponding variables. - Assign the outcome of the previous iteration (or initialization)
`tao_imp`

to the variable`prev_iter`

.