I have a data that looks like this (with more rows and more columns, but summarising here):
class section
a NA
b s1
c NA
d NA
a NA
b s2
c NA
d NA
a NA
b s3
c NA
d NA
Class a always comes before b, and c/d always comes after b. The data works as groups, so each abcd forms a separate group.
What I want to do is to assign acd to sections that their b belongs to, so the end file should look like this:
class section
a s1
b s1
c s1
d s1
a s2
b s2
c s2
d s2
a s3
b s3
c s3
d s3
I tried to do with for loop and if else, but i have so many rows and it takes too long, I also wanted to learn if there is an efficient way to do this with dplyr.
I appreciate any help, thank you!