Creation of unique codes based on number.

Hi,
I have a data of schools and student names and number of students in that school. Against each student, i need to create a code as shown in the dataframe data1. So in first school, there are 3 students then S1C1 to S1C3 will be created and so on.
Is this possible to do?

library(tidyverse)

data<-tibble::tribble(
                          ~selectedschoolid,             ~child_name_1, ~number,
        "SCH251-GMKPS NAVALURU-29090102801",          "Kushi  B Tadas",      3L,
        "SCH251-GMKPS NAVALURU-29090102801", "Kavya manjunath sarapur",      3L,
        "SCH251-GMKPS NAVALURU-29090102801",       "Gouri Hengannavar",      3L,
         "SCH294-GMPS BYAHATTI-29090700904",     "Manikanta guranavar",      4L,
         "SCH294-GMPS BYAHATTI-29090700904",    "Suprithgouda N Patil",      4L,
         "SCH294-GMPS BYAHATTI-29090700904",          "Darshan jainar",      4L,
         "SCH294-GMPS BYAHATTI-29090700904",       "Kiran B Nayakanur",      4L
        )

      

data1<-tibble::tribble(
                           ~selectedschoolid,             ~child_name_1, ~number, ~std_code,
         "SCH251-GMKPS NAVALURU-29090102801",          "Kushi  B Tadas",      3L,    "S1C1",
         "SCH251-GMKPS NAVALURU-29090102801", "Kavya manjunath sarapur",      3L,    "S1C2",
         "SCH251-GMKPS NAVALURU-29090102801",       "Gouri Hengannavar",      3L,    "S1C3",
          "SCH294-GMPS BYAHATTI-29090700904",     "Manikanta guranavar",      4L,    "S2C1",
          "SCH294-GMPS BYAHATTI-29090700904",    "Suprithgouda N Patil",      4L,    "S2C2",
          "SCH294-GMPS BYAHATTI-29090700904",          "Darshan jainar",      4L,    "S2C3",
          "SCH294-GMPS BYAHATTI-29090700904",       "Kiran B Nayakanur",      4L,    "S2C4"
         )
Created on 2022-07-12 by the reprex package (v2.0.1)

Haven’t you already asked this question and been given a solution?

1 Like

Yeah but there is a slight modification in the requirement. Because the earlier one had no student name. The name was creating problem with the code given in the older request.

That sounds like a follow up question and since your old topic is still open, I think it would be better to make it there to keep things tidy.

Yes it is. That problem was marked as solved. So I thought it's better to post a new topic.

As a rule of thumb, closely related follow up question should be made on the same topic, if the topic is still open. If the follow up question is considerably different than the original, then it should go in a new topic with its own descriptive title and you can link to the old one for reference.

I've responded to your original post to carry on the conversation there - that will create a more cohesive set of questions for people who come to look at this in the future.

A post was merged into an existing topic: Creating IDs based on the data given.

I'm just going to move the first post to the other topic and close this one

1 Like