So I have this data frame, in which some rows are duplicated in the "Species" column, and some aren't. There are NAs in all types of rows, both duplicated and not duplicated.
Species | A | B |
--------------------------------
Tilapia guineensis | 1 | 10 |
Tilapia guineensis | 1 | NA |
Tilapia zillii | 3 | 23 |
Tilapia zillii | 3 | NA |
Eutrigla gurnardus | 18 | 4 |
Caramila artida | 9 | NA |
Sprattus sprattus | 7 | 6 |
Spalili burcant | 11 | NA |
I want to remove that rows that have NAs in the B column, but only if they belong to a duplicate row. My output would be something like this:
Species | A | B |
--------------------------------
Tilapia guineensis | 1 | 10 |
Tilapia zillii | 3 | 23 |
Eutrigla gurnardus | 18 | 4 |
Caramila artida | 9 | NA |
Sprattus sprattus | 7 | 6 |
Spalili burcant | 11 | NA |
Basically, if a row is duplicated in the Species column and has a NA in the B column, I want to remove that row with the NA. However, if a row is unique in the Species column, I want to keep it even if it has NA.
Sorry if I'm being confusing, thanks in advance.
Reproducible data format:
df <- read.csv(text="
Species,A,B
Tilapia guineensis,1,10
Tilapia guineensis,1,NA
Tilapia zillii,3,23
Tilapia zillii,3,NA
Eutrigla gurnardus,18,4
Caramila artida,9,NA
Sprattus sprattus,7,6
Spalili burcant,11,NA")