I have a data frame df1
df1:
a c
1: 1 6
2: 2 8
3: 3 1
4: 45 3
5: 2 8
I need to find duplicate count of rows but also keeping the duplicate rows.The result should be like:
a c count
1: 1 6 1
2: 2 8 2
3: 3 1 1
4: 45 3 1
5: 2 8 2
as rows 2 and 5 are duplicates.But I am only able to get the solution that would give the answer
a c count
1: 1 6 1
2: 2 8 2
3: 3 1 1
4: 45 3 1
by doing
df1<-data.table(df1)
df1[, .N, by = list(a,c)]
How could I get the desired result?