Arranging grouped observations to be the same count for two ID's


Hello Everyone, I have this project where I am comparing ID1 and ID2. When I look into the file, there are instances where ID1 has more counts than ID2 after grouping them and vice versa.If this is the case, two things are to be done:

If ID1 is more than ID2, insert and empty cells(rows) starting from ID2 to species(This will shift the 2 in ID2 down to the next column). This will indicate that an observation in ID1 has missing values for all the other variable.
This results in

On the other hand, If ID2 has an observation to be more than ID1, we will delete the rows for that group observation. Thus, I would have deleted the portion highlighted in yellow. The part highlighted in green was shifted down to satisfy the first condition.
image

I have a lot of observations to look into for this and I have not been able to come up with any code to solve this. Will be grateful if anyone can help.

Thanks.

Hi, please provide a reproducible example, called a reprex. In this case it's a just snippet to add ID1 and ID2 to iris, since that's built in, plus the code you've tried.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.