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

后端 未结 3 1817
夕颜
夕颜 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条回答
  •  死守一世寂寞
    2021-01-19 21:21

    How about:

    length(unique(paste(dfTemp$var1, dfTemp$var2, dfTemp$var3)))==nrow(dfTemp)
    

    Paste variables into one string, get unique, and compare the length of this vector with number of rows in your dataframe.

提交回复
热议问题