unique() for more than one variable

后端 未结 4 1185
北荒
北荒 2020-11-29 02:25

I have the following data frame in R:

> str(df)
\'data.frame\':   545227 obs. of  15 variables:
 $ ykod : int  93 93 93 93 93 93 93 93 93 93 ...
 $ yad  :         


        
4条回答
  •  醉话见心
    2020-11-29 03:13

    How about using unique() itself?

    df <- data.frame(yad = c("BARBIE", "BARBIE", "BAKUGAN", "BAKUGAN"),
                     per = c("AYLIK",  "AYLIK",  "2 AYLIK", "2 AYLIK"),
                     hmm = 1:4)
    
    df
    #       yad     per hmm
    # 1  BARBIE   AYLIK   1
    # 2  BARBIE   AYLIK   2
    # 3 BAKUGAN 2 AYLIK   3
    # 4 BAKUGAN 2 AYLIK   4
    
    unique(df[c("yad", "per")])
    #       yad     per
    # 1  BARBIE   AYLIK
    # 3 BAKUGAN 2 AYLIK
    

提交回复
热议问题