I have a dataframe that I want to insert into a `mysql` database. Before inserting it, I need to fill in NA values in a column containing a non-unique key. The filled in values need to be shared across groups, but cannot overlap with any preexisting values in the sql table.

Assuming that the maximum key value in the table is 5. I would need:

```
id    group    key
 1      A       1
 2      A       1
 3      B       NA
 4      B       NA
 5      C       2
 6      D       NA

```

To become:

```
id    group    key
 1      A       1
 2      A       1
 3      B       6
 4      B       6
 5      C       2
 6      D       7

```