R: Checking if a set of variables forms a unique index

后端 未结 3 1813
夕颜
夕颜 2021-01-19 20:42

I have a large dataframe and I want to check whether the values a set of (factor) variables uniquely identifies each row of the data or not.

My current strategy is t

3条回答
  •  萌比男神i
    2021-01-19 21:19

    Perhaps anyDuplicated:

    anyDuplicated( dfTemp[, c("Var1", "Var2", "Var3") ] )
    

    or using dplyr:

    dfTemp %.% select(Var1, Var2, Var3) %.% anyDuplicated()
    

    This is still going to be wasteful though because anyDuplicated will first paste the columns into a character vector.

提交回复
热议问题