Hello- I am trying to figure out how to assign a number to each row (i.e., what I called "RowAssign" in the 'Medical residency education history' image), depending on whether a column variable in the previous row ("Practitioner Name") is different or the same as the current row. And if it is the same Name, assign a number in increasing order starting at 1 until the Name variable changes. My end goal is to take the data from long to wide using a join on the Practitioner Name, and each unique individual will have all of their education history on one row. I am working in RStudio 2022.02.3, build = 492, R version 4.2.1, and Windows 10.
I have written part of a function but it is incomplete:
RowAssign <- function(data, col1) {
for(i in 1:nrow(data)) {
if nrow-1 == unique(data$col1), 1, n+1}}
Thank you in advance!