I have a dataframe, df, in R that contains a column for sex and a column for age. During the data cleaning process, I noticed that for a few values the age and sex were flipped, so that the data looks like this:
SequenceNo Sex Age
1. sequence1 Male 65
2. sequence2 Female 45
3. sequence3 21 Male
4. sequence4 Female 12
I know I can go row by row and manually assign the correct values to fix the data, but is there an easy, unifying solution that can flip only the rows where the data is mismatched?