I have a dataframe 'df' that has three columns. Column three contains a series of randomly assigned numbers (1 to X) that often repeat themselves a number of times. Even though the column contains a set of randomly assigned numbers, they are sorted small to large to make this easier. Additionally, there are multiple entries for Site and Date, where each combination of Site and Date has the randomly selected numbers (1 to X). df currently looks like this (shortened for space purposes):
Site | Date | Minute |
---|---|---|
BMA | 44648 | 4 |
BMA | 44648 | 4 |
BMA | 44648 | 4 |
BMA | 44648 | 4 |
BMA | 44648 | 4 |
BMA | 44648 | 13 |
BMA | 44648 | 13 |
BMA | 44648 | 13 |
BMA | 44648 | 27 |
BMA | 44648 | 27 |
BMA | 44648 | 27 |
BMA | 44648 | 27 |
BMA | 44648 | 27 |
BMA | 44773 | 2 |
BMA | 44773 | 2 |
BMA | 44773 | 2 |
BMA | 44773 | 2 |
BMA | 44773 | 2 |
BMA | 44773 | 12 |
BMA | 44773 | 12 |
BMA | 44773 | 12 |
BMC | 44648 | 3 |
BMC | 44648 | 3 |
BMC | 44648 | 3 |
BMC | 44648 | 3 |
BMC | 44648 | 3 |
BMC | 44648 | 3 |
BMC | 44648 | 44 |
BMC | 44648 | 44 |
BMC | 44648 | 44 |
BMC | 44648 | 44 |
BMC | 44648 | 60 |
BMC | 44648 | 60 |
BMC | 44648 | 60 |
BMC | 44648 | 60 |
I want to convert those random numbers to an ordered set of numbers from 1-X (where X is the number of unique values for Minute, and so that a new ordered factor column is created that looks like this:
Site | Date | Minute | NewMinute |
---|---|---|---|
BMA | 44648 | 4 | 1 |
BMA | 44648 | 4 | 1 |
BMA | 44648 | 4 | 1 |
BMA | 44648 | 4 | 1 |
BMA | 44648 | 4 | 1 |
BMA | 44648 | 13 | 2 |
BMA | 44648 | 13 | 2 |
BMA | 44648 | 13 | 2 |
BMA | 44648 | 27 | 3 |
BMA | 44648 | 27 | 3 |
BMA | 44648 | 27 | 3 |
BMA | 44648 | 27 | 3 |
BMA | 44648 | 27 | 3 |
BMA | 44773 | 2 | 1 |
BMA | 44773 | 2 | 1 |
BMA | 44773 | 2 | 1 |
BMA | 44773 | 2 | 1 |
BMA | 44773 | 2 | 1 |
BMA | 44773 | 12 | 2 |
BMA | 44773 | 12 | 2 |
BMA | 44773 | 12 | 2 |
BMC | 44648 | 3 | 1 |
BMC | 44648 | 3 | 1 |
BMC | 44648 | 3 | 1 |
BMC | 44648 | 3 | 1 |
BMC | 44648 | 3 | 1 |
BMC | 44648 | 3 | 1 |
BMC | 44648 | 44 | 2 |
BMC | 44648 | 44 | 2 |
BMC | 44648 | 44 | 2 |
BMC | 44648 | 44 | 2 |
BMC | 44648 | 60 | 3 |
BMC | 44648 | 60 | 3 |
BMC | 44648 | 60 | 3 |
BMC | 44648 | 60 | 3 |
Thank you for your help!