- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find the count of duplicate rows if they are greater than n in R data frame?
To find the count of duplicate rows if they are greater than n in R data frame, we can follow the below steps −
- First of all, create a data frame.
- Then, count the duplicate rows if they are greater than a certain number using group_by_all, count, and filter function of dplyr package.
Create the data frame
Let's create a data frame as shown below −
x<-rpois(30,1) y<-rpois(30,1) df<-data.frame(x,y) df
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
x y 1 1 3 2 0 2 3 0 2 4 0 2 5 2 1 6 1 0 7 0 0 8 1 2 9 1 2 10 2 1 11 0 3 12 1 1 13 1 1 14 0 0 15 0 0 16 0 1 17 0 0 18 0 1 19 0 1 20 2 0 21 1 2 22 3 1 23 1 0 24 1 0 25 1 3 26 1 0 27 1 1 28 2 1 29 1 2 30 0 4
Count the duplicate rows if they are greater than a certain number
Loading dplyr package and using group_by_all, count, and filter function to find the count of duplicate rows if they are greater than 2 −
x<-rpois(30,1) y<-rpois(30,1) df<-data.frame(x,y) library(dplyr) df%>%group_by_all()%>%count()%>%filter(n>2)
Output
# A tibble: 7 x 3 # Groups: x, y [7] x y n <int> <int> <int> 1 0 0 4 2 0 1 3 3 0 2 3 4 1 0 4 5 1 1 3 6 1 2 4 7 2 1 3
- Related Articles
- How to count the number of duplicate rows in an R data frame?
- Replace all values in an R data frame if they are greater than a certain value.
- How to subset rows of an R data frame if any columns have values greater than a certain value?
- How to subset rows of an R data frame if all columns have values greater than a certain value
- How to remove rows in an R data frame column that has duplicate values greater than or equal to a certain number of times?
- How to remove duplicate rows in an R data frame if exists in two columns?
- How to delete a row from an R data frame if any value in the row is greater than n?
- How to find the column mean of first n number of rows in R data frame?
- How to check if a variable contains number greater than 1 in an R data frame?
- How to find the percent of NA’s in R data frame rows?
- How to find the unique rows in an R data frame?
- How to renumber rows if they are unordered in R?
- How to find the index of values in an R data frame column if they occur once?
- How to select rows of a data frame that are not in other data frame in R?
- How to subset rows of an R data frame based on duplicate values in a particular column?

Advertisements