I have a large dataset and have tried finding an answer to this online but can't find one which answers my problem. I want to exclude a number of individuals in my dataset.
I have two columns of data in my dataset which are made up of a number of dates. I want to remove all individuals where date A is before dateB.
I've tried a variety of things but I can't work it out. When I have successfully removed these individuals all my other columns in the datset have NA in them versus the value they are meant to show.
If my dataset is called cohort, and dateA and dateB are the names of the columns, then this is what I tried to remove the individuals:
cohort2 <- cohort[!(cohort$dateA<cohort$dateB),]
cohort3 <- subset(cohort, cohort$dateA!<cohort$dateB)
Example of what my dataset looks like, I want to remove row 4 of the data in this case as date A occurs before date B. Thereby creating a new cohort which has the first three rows and the last row.
DateA DateB
1/1/16 1/1/15
2/2/16 2/2/15
3/3/16 3/3/15
4/4/15 4/4/16
NA___ 5/5/15