I want to delete one of duplicate rows when the condition is met.
When "Client" and "year" are the same and "type" is different delete one of the duplicate row (which corresponds to a larger value in "cost"). But is DO NOT filter if all "client", "year" and "type" are the same.
client<- c(1,1,1,2,2,3,3,4, 5,5)
year <- c(2000, 2010, 2000, 2003, 2007, 2009, 2009, 2012, 2017, 2017)
type<-c("A", "A", "B", "B", "C","D","D", "A" , "C", "D")
cost<- c(34,56,78, 45,12,56,67,23,10, 89)
data<- tibble(cient,year, type,value)
client year type cost
1 1 2000 A 34
2 1 2010 A 56
3 1 2000 B 78
4 2 2003 B 45
5 2 2007 C 12
6 3 2009 D 56
7 3 2009 D 67
8 4 2012 A 23
9 5 2017 C 10
10 5 2017 D 89
As a result row # 2 and row #10 should get deleted and the result should look like this:
Cient type value
client year type cost
1 1 2000 A 34
2 1 2000 B 78
3 2 2003 B 45
4 2 2007 C 12
5 3 2009 D 56
6 3 2009 D 67
7 4 2012 A 23
8 5 2017 C 10
I am new to tidyverse and couldn't write a command that will filter a row with condition.
Thanks in advance for your help