My non-survey dataset looks like this
I want to remove any row of ID that has one instance of either AICU/BICU/NICU in the location variable
In addition to removing the row that has ID 1 and Location AICU ( first example) , I want to remove the 4th example too as ID is 1 and the ID had either one instance of AICU/BICU/NICU
In other words, I want to retain only ID's that have never been even once in AICU/BICU/NICU.
The sample size is around 50,000, so cannot do it manually.
If the removal process is carried out correctly, the resultant dataset would look like this
I suspect it has to be a looping code, but can't seem to wrap my mind on how to start. I appreciate any insight.
Thanks for your time
ID | Location |
1 | AICU |
1 | BICU |
1 | NICU |
1 | 4W |
1 | 4W |
1 | 4W |
1 | 4W |
1 | 4W |
2 | 5E |
2 | 5E |
2 | 5E |
3 | NICU |
3 | 6E |
3 | 6E |
I want to remove any row of ID that has one instance of either AICU/BICU/NICU in the location variable
In addition to removing the row that has ID 1 and Location AICU ( first example) , I want to remove the 4th example too as ID is 1 and the ID had either one instance of AICU/BICU/NICU
In other words, I want to retain only ID's that have never been even once in AICU/BICU/NICU.
The sample size is around 50,000, so cannot do it manually.
If the removal process is carried out correctly, the resultant dataset would look like this
ID | Location |
2 | 5E |
2 | 5E |
2 | 5E |
I suspect it has to be a looping code, but can't seem to wrap my mind on how to start. I appreciate any insight.
Thanks for your time