This question already has an answer here:
- Count number of rows within each group 12 answers
I have a data frame like the following example
a = c(1, 1, 1, 2, 2, 3, 4, 4)
b = c(3.5, 3.5, 2.5, 2, 2, 1, 2.2, 7)
df <-data.frame(a,b)
I can remove duplicated rows from R data frame by the following code, but how can I find how many times each duplicated rows repeated? I need the result as a vector.
unique(df)
or
df[!duplicated(df), ]
Here are two approaches.
You could always kill two birds with the one stone:
Here is solution using function
ddply()
from libraryplyr
Using dplyr:
or