I have a dataframe (df) that looks like this:
School Student Year
A 10 1999
A 10 2000
A 20 1999
A 20 2000
A 20 2001
B 10 1999
B 10 2000
And I would like to create a person column IDso that df looks like this:
ID School Student Year
1 A 10 1999
1 A 10 2000
2 A 20 1999
2 A 20 2000
2 A 20 2001
3 B 10 1999
3 B 10 2000
In other words, the variable IDindicates in which staff it is in the data set, taking into account both the number of students and school membership (here we have only 3 students).
I did df$ID <- df$Studentand tried to request a +1 if it c("School", "Student)was unique. He does not work. Help evaluate.
source
share