Remove duplicates column combinations from a dataframe in R

前端 未结 4 1076
夕颜
夕颜 2020-12-06 14:06

I want to remove duplicate combinations of sessionid, qf and qn from the following data

               sessionid             qf        qn         city
1  9         


        
4条回答
  •  一生所求
    2020-12-06 14:53

    duplicated() has a method for data.frames, which is designed for just this sort of task:

    df <- data.frame(a = c(1:4, 1:4), 
                     b = c(4:1, 4:1), 
                     d = LETTERS[1:8])
    
    df[!duplicated(df[c("a", "b")]),]
    #   a b d
    # 1 1 4 A
    # 2 2 3 B
    # 3 3 2 C
    # 4 4 1 D
    

提交回复
热议问题