Suppose I have the following data table:
dt <- data.table(id = c(1, 1, 2, 2, 3, 3, 4, 4), v = 1:8)
id v
1: 1 1
2: 1 2
3: 2 3
4: 2 4
5: 3 5
6: 3 6
7: 4 7
8: 4 8
When I drop the rows with id = 2, I get the following:
dt <- dt[id != 2]
id v
1: 1 1
2: 1 2
3: 3 5
4: 3 6
5: 4 7
6: 4 8
At this point, how could I shift the values in id so that there is no gap in the integer values in id, like the following?
id v
1: 1 1
2: 1 2
3: 2 5
4: 2 6
5: 3 7
6: 3 8