Hi.
I have a data of schools with the number of students. What I want is that I need to create codes/ids for each student. For example if the school-1 has 4 students, then the student codes is S1C1, S1C2, S1C3, S1C4.
This process has to be repeated for all schools. My original data has 140 schools.
My desired output is given in data frame "student_code". Is this possible?
library(tidyverse)
school_data<-tibble::tribble(
~sch_name, ~total_students,
"HPS KIRESUR", 2L,
"GHPS KOTUR", 3L,
"LPS HEBSUR", 5L,
"GHPS NEKAR NAGAR HALE HUBLI", 4L,
"GLPS CHABBI PLOT NEKAR NAGAR HALE HUBLI", 5L
)
#desired output
student_code<-tibble::tribble(
~sch_name, ~student_code,
"HPS KIRESUR", "S1C1",
"HPS KIRESUR", "S1C2",
"GHPS KOTUR", "S2C1",
"GHPS KOTUR", "S2C2",
"GHPS KOTUR", "S2C3",
"LPS HEBSUR", "S3C1",
"LPS HEBSUR", "S3C2",
"LPS HEBSUR", "S3C3",
"LPS HEBSUR", "S3C4",
"LPS HEBSUR", "S3C5",
"GHPS NEKAR NAGAR HALE HUBLI", "S4C1",
"GHPS NEKAR NAGAR HALE HUBLI", "S4C2",
"GHPS NEKAR NAGAR HALE HUBLI", "S4C3",
"GHPS NEKAR NAGAR HALE HUBLI", "S4C4",
"GLPS CHABBI PLOT NEKAR NAGAR HALE HUBLI", "S5C1",
"GLPS CHABBI PLOT NEKAR NAGAR HALE HUBLI", "S5C2",
"GLPS CHABBI PLOT NEKAR NAGAR HALE HUBLI", "S5C3",
"GLPS CHABBI PLOT NEKAR NAGAR HALE HUBLI", "S5C4",
"GLPS CHABBI PLOT NEKAR NAGAR HALE HUBLI", "S5C5"
)
Created on 2022-06-30 by the reprex package (v2.0.1)