I have a data.frame in R that looks like the following:
> inputtable <- data.frame(TN = c("T","N","T","N","N","T","T","N"),
+ Value = c(1,1,2,2,2,3,3,5))
> inputtable
TN Value
1 T 1
2 N 1
3 T 2
4 N 2
5 N 2
6 T 3
7 T 3
8 N 5
I want to remove values that duplicated in the Value
column, but ONLY if one row has "T" and the other has "N" in the TN
column.
I played around with duplicated, but this doesn't work the way I've coded it:
TNoverlaps.duprem <- TNoverlaps[ !(duplicated(TNoverlaps$Barcode) & ("T" %in% TNoverlaps$TN & "N" %in% TNoverlaps$TN)), ]
and
TNoverlaps.duprem <- TNoverlaps[ duplicated(TNoverlaps$Barcode) & !duplicated(TNoverlaps$Barcode, TNoverlaps$TN), ]
If there are more than two rows, as in rows 3-5 above, I want to remove all of those, because at least one is "T" and one is "N" in the TN
column.
Here's the output I want
> outputtable
TN Value
6 T 3
7 T 3
8 N 5
I found plenty of questions about duplicated rows, and removing rows based on multiple columns. But I didn't see one that did something like this.