I have this dataframe below and I want to detect missing Visits for each subject, how can I sort the visits by Subject and extract only the records that has missing values ? Please check the two type of output needed.
Part 1 : So depending on the highest number in the Column "Visit" for all Subjects missing records for all subjects needs to show up :
Subject Visit X1 X2
A 1 1647143 1672244
A 2 1672244 1689707
A 4 1689707 1713090
B 1 1735352 1760283
B 2 1760283 1788062
B 7 1788062 1789885
B 9 1789885 1790728
The output would be :
Subject Visit X1 X2
A 3 1647143 1672244
A 5 1672244 1689707
A 6 1689707 1713090
A 7 1647143 1672244
A 8 1672244 1689707
A 9 1689707 1713090
B 3 1735352 1760283
B 4 1760283 1788062
B 5 1788062 1789885
B 6 1789885 1790728
B 8 1789885 1790728
Part 2 : So depending on the highest number in the Column "Visit" for each specific Subject missing records in the Sequence of visits needs to show up : Example Output :
Subject Visit X1 X2
A 3 1647143 1672244
B 3 1735352 1760283
B 4 1760283 1788062
B 5 1788062 1789885
B 6 1789885 1790728
B 8 1789885 1790728