-1

I have this dataframe

`> str(AMComp)
'data.frame':   1300697 obs. of  8 variables:
 $ Commodity.Code       : chr  "H0-842481" "H0-842481" "H0-842481" "H0-842481" ...
 $ Commodity.Description: chr  "Agricultural sprays and powder dispersers" "Agricultural sprays and powder dispersers" "Agricultural sprays and powder dispersers" "Agricultural sprays and powder dispersers" ...
 $ Period               : int  1988 1988 1988 1988 1988 1988 1988 1988 1988 1988 ...
 $ Reporter             : chr  "Australia" "Australia" "Australia" "Australia" ...
 $ Partner              : chr  "Areas, nes" "Argentina" "Austria" "Brazil" ...
 $ Value.Import         : num  156 NA 425739 16623 6930 ...
 $ Value.Export         : num  NA 3025 NA NA 70355 ...
 $ Trade.Difference     : num  NA NA NA NA -63425 ...`

I have noticed that in the variable Reporter and in the variable Partner there are some inconsistencies. For instance some Reporters claim to have imported or exported things to itself.

Now, I have to get rid of those inconsistencies. All cases in which the variable Reporter and the variable Partner coincide should be flagged in order to eventually delete those observations.

Ferdi
  • 540
  • 3
  • 12
  • 23
Ileeo
  • 25
  • 1
  • 7
  • Maybe `AMComp <- AMComp[AMComp$Reporter != AMComp$Partner, ]` ? – zx8754 Oct 17 '16 at 12:19
  • Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – zx8754 Oct 17 '16 at 12:19

1 Answers1

1

You can create a simple flag that's 1 when Reporter is equal to Partner and 0 otherwise:

AMComp$flag <- ifelse(AMComp$Reporter == AMComp$Partner, 1,0)

If you want to eliminate the problematic entries you can then simply do:

AMComp_clean <- AMComp[AMComp$flag == 0,]

Where AMComp_clean is the new cleaned dataframe.

thepule
  • 1,721
  • 1
  • 12
  • 22