0

enter image description here

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!

Phil
  • 7,287
  • 3
  • 36
  • 66
NataliN
  • 1
  • 1
  • 2
    Is this what you are looking for? https://stackoverflow.com/a/12925090/12400385 – nniloc Aug 26 '22 at 22:30
  • Greetings! Typically it is recommended to provide a minimally reproducible dataset with your question. One way of achieving this is by using the `dput` command. You can check out how to do this at this video: https://youtu.be/3EID3P1oisg – Shawn Hemelstrand Aug 30 '22 at 23:02

0 Answers0