I have a large dataframe (698764 X 9) that looks similar in format to:
df <- data.frame(id = c(1, 2, 1, 4), units = c(2, 2, 2, 5), region = c("US", "CA", "US", "IN))
As we can see the first and third row are exactly the same. I would like to extract the duplicated row and then count how many times it was duplicated in the data so that the output would look like
duplicates <- data.frame(id = 1, units = 2, region = "US", times = 2)
where "times" is the number of times the row is duplicated.
I extracted the duplicated rows using
new_df <- df[duplicated(df),]
but I am not sure how to count the number of occurences.