get rows of unique values by group

前端 未结 4 778
抹茶落季
抹茶落季 2021-01-19 02:29

I have a data.table and want to pick those lines of the data.table where some values of a variable x are unique relative to another variable y

It\'s possible to get

4条回答
  •  忘掉有多难
    2021-01-19 03:12

    The idiomatic data.table way is:

    require(data.table)
    unique(dt, by = c("y", "x"))
    #    y x z
    # 1: a 1 1
    # 2: a 2 2
    # 3: b 3 4
    # 4: b 2 5
    # 5: b 1 6
    

提交回复
热议问题