id re_enter_id date score
101 NA 01.1.2021 60
102 101 12.1.2021 65
103 102 17.1.2021 70
104 103 18.1.2021 68
105 NA 25.1.2021 81
106 NA 03.1.2021 55
107 NA 10.1.2021 67
108 107 11.1.2021 69
109 NA 09.1.2021 85
About data:
The data represents the students who entered to a examination multiple times. It consists of three columns student id, student id re-entered examination or not, date of examination and score to the exam.
If we consider student with id 101, he entered in exam on 1.1.2021, again entered to the exam 12.1.2021 but with student id 102 and so on. So first 4 rows of the data is related to student 101.
Similarly for student 107, who entered to the exam on 10.1.2021, re-entered on 11.1.2021. So student 107 and 108 are same.
Other students like 105,106 entered to the exam only once.
Topic:
The requirement is I need to search for similar ids and extract all related data for a student.
So I was trying to create a function which takes id as parameter, f(id). Hence f(102) will return all data related to 101 i.e. first 4 rows and hence f(101) = f(102) = f(103) = f(104).
Similarly f(107) = f(108).
How can I create this function with sequential string search and find out the data related to a student?
Thanks in advance.