Getting unique rows of a table and their numbers

前端 未结 3 783
夕颜
夕颜 2020-12-12 01:44

I have a dataframe:

id  y   z
oX  79  100
oX  23  46
oX  10  29
uM  12  90
uT  43  50
uT  13  99

I would like to keeep unique rows based on

相关标签:
3条回答
  • 2020-12-12 02:08

    this will do what you want :

    > as.data.frame(table(a$id))
      Var1 Freq
    1   oX    3
    2   uM    1
    3   uT    2
    
    0 讨论(0)
  • 2020-12-12 02:11

    Just wanted to post another alternative, consider data.table

    > library(data.table)
    > data.table(mydf)[,.N, by="id"]
       id N
    1: oX 3
    2: uM 1
    3: uT 2
    
    0 讨论(0)
  • 2020-12-12 02:14

    Assuming your data.frame is called "mydf", table should work just fine:

    table(mydf$id)
    #
    # oX uM uT 
    #  3  1  2 
    
    0 讨论(0)
提交回复
热议问题