I have a data frame which is the result of the left join. Sample data is provided below:
P.I.D.. Status List.year CURRENT_LAND_VALUE CURRENT_IMPROVEMENT_VALUE
<chr> <chr> <dbl> <dbl> <dbl>
1 003-913-627 X 2000 NA NA
2 003-913-627 T 2010 1578000 1201000
3 003-913-627 S 2018 NA NA
4 003-913-627 S 2018 2814000 901000
5 003-913-627 S 2002 NA NA
6 003-913-627 T 2007 390000 282000
7 003-913-627 T 2007 295000 180000
8 003-913-627 S 2008 464000 391000
9 003-913-627 S 2008 339000 246000
10 003-913-627 X 2009 339000 246000
11 003-913-627 X 2009 464000 391000
Sorry, I tried to usedput to generate code for the data but when I tried, it gave me some unrelated result which doesn't represent the table shown above
As can be seen for year 2018 and PID 003-913-627, two rows are shown. One has a number for CURRENT_LAND_VALUE and CURRENT_IMPROVEMENT_VALUE and one row includes NA. What I want to do is removing the row which has NA value only if the row is duplicate (which means we have another row with the same PID and List.year. In some cases like the first row, since there is no same row with PID 003-913-627 and List.Year 2000 the NA shouldn't be removed. The expected result for the above data frame is:
P.I.D.. Status List.year CURRENT_LAND_VALUE CURRENT_IMPROVEMENT_VALUE
<chr> <chr> <dbl> <dbl> <dbl>
1 003-913-627 X 2000 NA NA
2 003-913-627 T 2010 1578000 1201000
4 003-913-627 S 2018 2814000 901000
5 003-913-627 S 2002 NA NA
6 003-913-627 T 2007 390000 282000
7 003-913-627 T 2007 295000 180000
8 003-913-627 S 2008 464000 391000
9 003-913-627 S 2008 339000 246000
10 003-913-627 X 2009 339000 246000
11 003-913-627 X 2009 464000 391000
In summary: I want to remove rows that have NA in "CURRENT_LAND_VALUE" and "CURRENT_IMPROVEMENT_VALUE" only if there is already a row with same "PID" and "List.Year" which has actual value for "CURRENT_IMPROVEMENT_VALUE" or "CURRENT_LAND_VALUE"
how can I do this?