Let's say we have the following:
c("A", "A", "B") %>%
cbind(1:3) %>%
data.frame() -> testdf
We want to remove from the dataframe all instances where there was a duplicate in the first variable. Usually we would use something like this:
testdf2 <- testdf[!duplicated(testdf$.),]
However, testdf2
looks like this:
. V2
A 1
B 3
This is not what I was looking for - since the value A was duplicated, I want to remove all cases that have A in the first variable. I want my output to be like this:
. V2
B 3
Is there a function that could produce this?
try testdf[!duplicated(testdf$.)&!duplicated(testdf$.,fromLast = TRUE),]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With