I have below dataset where I want to create a unique column ("New_ID") based on the duplicate record ID column using "Record_ID".
Dummy dataframe:
df <- data.frame(Stores=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13,14,15,16,17,18,19,20),
Record_ID=c(1, 1, 2, 3, 3, 3, 4, 4, 4, 4,4,4,4,5,5,6,7,7,7,8))
Expected Result:
| Stores | Record_ID | New_ID |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 1 | 2 |
| 3 | 2 | 1 |
| 4 | 3 | 1 |
| 5 | 3 | 2 |
| 6 | 3 | 3 |
| 7 | 4 | 1 |
| 8 | 4 | 2 |
| 9 | 4 | 3 |
| 10 | 4 | 4 |
| 11 | 4 | 5 |
| 12 | 4 | 6 |
| 13 | 4 | 7 |
| 14 | 5 | 1 |
| 15 | 5 | 2 |
| 16 | 6 | 1 |
| 17 | 7 | 1 |
| 18 | 7 | 2 |
| 19 | 7 | 3 |
| 20 | 8 | 1 |
I tried using dplyr::mutate(New_ID = rowid(Record_ID)) but it's showing the below error.
Error in rowid(Row_ID) : could not find function "rowid"
Also m not able to download package data.table, I guess this might be the issue for the error msg.
Please provide solution for this.