I have below dataset where I want to create a "New_Record_ID" column using the "Current_Record_ID" and "Stores". I'am trying to make "New_Record_ID" increment every 2 Stores based on "Current_Record_ID".
for example: If "Current_Record_ID" is having 2 stores then the record ID will remain same. But if it exceeds 2 Stores then a new record ID (increment '+1') will be assigned to it and similar will follow for the next record IDs in the column "Current_Record_ID".
Dummy dataframe:
df <- data.frame(Stores=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12),Current_Record_ID=c(1, 1, 2, 2, 2, 2, 3, 3, 3, 3,4,4))
Stores | Current_Record_ID |
---|---|
1 | 1 |
2 | 1 |
3 | 2 |
4 | 2 |
5 | 2 |
6 | 2 |
7 | 3 |
8 | 3 |
9 | 3 |
10 | 3 |
11 | 4 |
12 | 4 |
Expected Result
Stores | Current_Record_ID | New_Record_ID |
---|---|---|
1 | 1 | 1 |
2 | 1 | 1 |
3 | 2 | 2 |
4 | 2 | 2 |
5 | 2 | 3 |
6 | 2 | 3 |
7 | 3 | 4 |
8 | 3 | 4 |
9 | 3 | 5 |
10 | 3 | 5 |
11 | 4 | 6 |
12 | 4 | 6 |
Second Part:
Sample 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),
Current_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 | Current_Record_ID | New_Record_ID |
---|---|---|
1 | 1 | 1 |
2 | 1 | 1 |
3 | 2 | 2 |
4 | 3 | 3 |
5 | 3 | 3 |
6 | 3 | 4 |
7 | 4 | 5 |
8 | 4 | 5 |
9 | 4 | 6 |
10 | 4 | 6 |
11 | 4 | 7 |
12 | 4 | 7 |
13 | 4 | 8 |
14 | 5 | 9 |
15 | 5 | 9 |
16 | 6 | 10 |
17 | 7 | 11 |
18 | 7 | 11 |
19 | 7 | 12 |
20 | 8 | 13 |
*Also if we have a larger data set of n stores and Currect_Record_ID and we want to fix stores/not to exceed 100 counts. How can we will create the New_record_ID .?