Subset with unique cases, based on multiple columns

前端 未结 7 2163
执笔经年
执笔经年 2020-12-04 12:06

I\'d like to subset a dataframe to include only rows that have unique combinations of three columns. My situation is similar to the one presented in this question, but I\'d

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 12:43

    A non-elegant but functional way is to paste the entries of a given row together and find which are unique (or non-unique) rows, something like:

    df.vector=apply(df,1,FUN=function(x) {paste(x,collapse="")})
    df.table=table(df.vector)
    

    then get the indexes of the duplicates with something like:

    which(df.vector%in%names(which(df.table>1)))
    

提交回复
热议问题