r - How to drop non-unique rows based on multiple columns -
i have data frame:
data.frame(name= c("b","d","d","e"),date=as.date(c("2015-01-01","2015-01-02","2015-02-02","2015-03-02")),s=c("e","b","b","g"),num=c(1,2,2,3)) name date s num 1 b 2015-01-01 e 1 2 d 2015-01-02 b 2 3 d 2015-02-02 b 2 4 e 2015-03-02 g 3
and want drop rows not unique in case above want drop rows 2 & 3 because have same values name
, date
, s
& num
. results be:
name date s num 1 b 2015-01-01 e 1 2 e 2015-03-02 g 3
any ideas?
if understand correctly have remove rows seen duplicated
df1[!duplicated(df1) & !duplicated(df1, fromlast = true) ,]
using data:
df1 <- data.frame( name= c("b","d","d","e"), date=as.date(c("2015-01-01","2015-01-02","2015-01-02","2015-03-02")), s=c("e","b","b","g"), num=c(1,2,2,3))
the result is
# name date s num # 1 b 2015-01-01 e 1 # 4 e 2015-03-02 g 3