Function duplicated in R performs duplicate row search. If we want to remove the duplicates, we need just to write df[!duplicated(df),]
and duplicates will be removed from data frame.
But how to find the indices of duplicated data? If duplicated
returns TRUE on some row, it means, that this is the second occurence of such a row in the data frame and its index can be easily obtained. How to obtain the index of first occurence of this row? Or, in other words, an index with which the duplicated row is identical?
I could make a loop on data.frame, but I think there is a more elegant answer on this question.
which(duplicated(df) | duplicated(df, fromLast = TRUE))
. Then you get the indices of duplicated rows. – Profiteer