I have a specific problem I'm trying to solve within a dataframe using R. Here are the columns and a few rows of sample data:
I want to write a function that finds ZIP where there is more than one FIPS and more than one PROMO. So to put it another way, ZIPS that cross FIPS with different PROMO. I don't need to worry about COUNTY, FACTOR_X and FACTOR_Y but I do need to keep them.
There are three possible PROMO levels (LOW, ZERO, VARIABLE). If a ZIP is present in more than one FIPS and the PROMO is not distinct within the subset, the STATUS is FAIL. If however, a ZIP is present in more than one FIPS and the PROMO is distinct (the same) within the subset, the STATUS is PASS.
Here are some sample output
ZIP,ST_COUNTY,FIPS,FACTOR_X,FACTOR_Y,PROMO,STATUS
8520,NJ MERCER,34021,XXX,YYY,VARIABLE,FAIL
8520,NJ MIDDLESEX,34023,XXX,YYY,ZERO,FAIL
8525,NJ XUNTERDON,34019,XXX,YYY,LOW,FAIL
8525,NJ MERCER,34021,XXX,YYY,VARIABLE,FAIL
8540,NJ MERCER,34021,XXX,YYY,VARIABLE,FAIL
8540,NJ MIDDLESEX,34023,XXX,YYY,ZERO,FAIL
8540,NJ SOMERSET,34035,XXX,YYY,ZERO,FAIL
8558,NJ XUNTERDON,34019,XXX,YYY,LOW,FAIL
8558,NJ MERCER,34021,XXX,YYY,VARIABLE,FAIL
8558,NJ SOMERSET,34035,XXX,YYY,ZERO,FAIL
23117,VA GOOCXLAND,51075,XXX,YYY,ZERO,FAIL
23117,VA LOUISA,51109,XXX,YYY,LOW,FAIL
23117,VA SPOTSYLVANIA,51177,XXX,YYY,LOW,FAIL
23117,VA SPOTSYLVANIA,51177,XXX,YYY,ZERO,FAIL
78015,TX BEXAR,48029,XXX,YYY,ZERO,FAIL
78015,TX BEXAR,48029,XXX,YYY,ZERO,FAIL
78015,TX COMAL,48091,XXX,YYY,LOW,FAIL
78015,TX COMAL,48091,XXX,YYY,ZERO,FAIL
78015,TX KENDALL,48259,XXX,YYY,LOW,FAIL
78015,TX KENDALL,48259,XXX,YYY,ZERO,FAIL
1906,MA ESSEX,25009,XXX,YYY,LOW,PASS
1906,MA MIDDLESEX,25017,XXX,YYY,LOW,PASS
1906,MA SUFFOLK,25025,XXX,YYY,LOW,PASS
16127,PA BUTLER,42019,XXX,YYY,ZERO,PASS
16127,PA LAWRENCE,42073,XXX,YYY,ZERO,PASS
16127,PA MERCER,42085,XXX,YYY,ZERO,PASS
16127,PA VENANGO,42121,XXX,YYY,ZERO,PASS
For output, I would like to split into two files with the original columns plus the new STATUS column. The first file would be ZIP_PASS with all STATUS == PASS and the second file would be ZIP_FAIL with all STATUS == FAIL
=======