Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R
  • Data Types
  • String
  • Array
  • Vector
  • Lists
  • Matrices
  • Oops in R
Open In App
Next Article:
How to find missing values in a matrix in R
Next article icon

How to find duplicate values in a list in R

Last Updated : 12 Apr, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will see how to find duplicate values in a list in the R Programming Language in different scenarios.

Finding duplicate values in a List

In R, the duplicated() function is used to find the duplicate values present in the R objects. This function determines which elements of a List are duplicates and returns a logical vector (Holds TRUE/FALSE values) indicating which elements are duplicates. TRUE is returned if the element already exists. Otherwise, FALSE will be returned.

Syntax:

duplicated(List_name)

Here, List_name is the input list.

Let's have a list with 10 values and find the duplicate values.

R
# Create a List List_data =list(1,2,3,4,5,6,7,5,4,3) print(List_data)  # Find duplicates in the above List print(duplicated(List_data)) 

Output:

[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3

[[4]]
[1] 4

[[5]]
[1] 5

[[6]]
[1] 6

[[7]]
[1] 7

[[8]]
[1] 5

[[9]]
[1] 4

[[10]]
[1] 3

[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE

We can see that last three elements in the List are duplicated. So TRUE is returned for them.

Let's have a list that hold 2 lists and find duplicates in each of the list separately.

R
# Create a List with 2 lists List_data =list(list1=list(100,200,300,300,300),                 list2=list("Java","HTML","PHP","JSP","Statistics")) print(List_data)  # Find duplicates in list1 from List_data print(duplicated(List_data$list1))  # Find duplicates in list2 from List_data print(duplicated(List_data$list2)) 

Output:

$list1
$list1[[1]]
[1] 100

$list1[[2]]
[1] 200

$list1[[3]]
[1] 300

$list1[[4]]
[1] 300

$list1[[5]]
[1] 300


$list2
$list2[[1]]
[1] "Java"

$list2[[2]]
[1] "HTML"

$list2[[3]]
[1] "PHP"

$list2[[4]]
[1] "JSP"

$list2[[5]]
[1] "Statistics"

[1] FALSE FALSE FALSE TRUE TRUE

[1] FALSE FALSE FALSE FALSE FALSE

There are two duplicates in list1.

Let's create a List having three vectors and find the duplicates in each vector.

R
# Create a List with 3 vectors List_data =list(Id=c(1,2,3,4,5,4,5),Subject=c("Java","HTML","HTML","Python"),                 Marks=c(100,89,78,69,80)) print(List_data)  # Find duplicates in the Id duplicated(List_data$Id)  # Find duplicates in the Subject duplicated(List_data$Subject)  # Find duplicates in the Marks duplicated(List_data$Marks) 

Output:

$Id
[1] 1 2 3 4 5 4 5

$Subject
[1] "Java" "HTML" "HTML" "Python"

$Marks
[1] 100 89 78 69 80

[1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE

[1] FALSE FALSE TRUE FALSE

[1] FALSE FALSE FALSE FALSE FALSE
  1. Id holds two duplicate values i.e 4 and 5
  2. Subject holds one duplicate value i.e "HTML"
  3. There are no duplicates in the Marks vector.

Let's create a List having 2 vectors and return total number of duplicate elements. To do this we need to use the sum() function and pass the duplicated() function as a parameter to it.

R
# Create a List with 2 vectors List_data =list(Id=c(1,2,3,4,5,4,5),Subject=c("Java","HTML","HTML","Python")) print(List_data)  # Find duplicates in the Id sum(duplicated(List_data$Id))  # Find duplicates in the Subject sum(duplicated(List_data$Subject)) 

Output:

$Id
[1] 1 2 3 4 5 4 5

$Subject
[1] "Java" "HTML" "HTML" "Python"

[1] 2

[1] 1

There are 2 duplicates in the Id vector and one duplicate in the Subject vector.

Conclusion

In conclusion, identifying duplicate values in a list in R is essential for data cleaning and quality assurance. By utilizing various methods such as the duplicated() function we can efficiently detect and handle duplicate values.


Next Article
How to find missing values in a matrix in R
author
sravankumar_171fa07058
Improve
Article Tags :
  • R Language
  • R-List

Similar Reads

  • How to find duplicate values in a factor in R
    finding duplicates in data is an important step in data analysis and management to ensure data quality, accuracy, and efficiency. In this article, we will see several approaches to finding duplicate values in a factor in the R Programming Language. It can be done with two methods Using duplicated()
    2 min read
  • How to find missing values in a list in R
    Missing values are frequently encountered in data analysis. In R Programming Language effectively dealing with missing data is critical for correct analysis and interpretation. Whether you're a seasoned data scientist or a new R user, understanding how to identify missing values is critical. In this
    3 min read
  • How to find missing values in a matrix in R
    In this article, we will examine various methods for finding missing values in a matrix by using R Programming Language. What are missing values?The data points in a dataset that are missing for a particular variable are known as missing values. These missing values are represented in various ways s
    3 min read
  • How to Find Duplicate Rows in PL/SQL
    Finding duplicate rows is a widespread requirement when dealing with database analysis tasks. Duplicate rows often create problems in analyzing tasks. Detecting them is very important. PL/SQL is a procedural extension for SQL. We can write custom scripts with the help of PL/SQL and thus identifying
    5 min read
  • How to create a list in R
    In this article, we will discuss What is a list and various methods to create a list using R Programming Language. What is a list?A list is the one-dimensional heterogeneous data i.e., which stores the data of various types such as integers, float, strings, logical values, and characters. These list
    2 min read
  • How to Find Duplicate Records in SQL?
    To find duplicate records in SQL, we can use the GROUP BY and HAVING clauses. The GROUP BY clause allows us to group values in a column, and the COUNT function in the HAVING clause shows the count of the values in a group. Using the HAVING clause with a condition of COUNT(*) > 1, we can identify
    3 min read
  • Lookup Top N Values Ignoring Duplicates in Excel
    Excel is one of the best ways to organize and present a large amount of data. However, finding data in excel requires certain commands. In order to lookup top N values ignoring duplicates, it is important to first learn how to find top N values in Excel. Top N values mean finding the largest value,
    2 min read
  • How to Find Unique Values and Sort Them in R
    Finding and Sorting unique values is a common task in R for data cleaning, exploration, and analysis. In this article, we will explore different methods to find unique values and sort them in R Programming Language. Using sort() with unique()In this approach, we use the unique() function to find uni
    2 min read
  • SQL Query to Find Duplicate Names in a Table
    Duplicate records in a database can create confusion, generate incorrect results, and waste storage space. It’s essential to identify and remove duplicates to maintain data accuracy and database performance. In this article, we’ll discuss the reasons for duplicates, how to find duplicate records in
    3 min read
  • How to Find and Remove Duplicates in Excel
    Removing duplicates in Excel is essential when cleaning up data to ensure accuracy and avoid redundancy. Whether you’re working with small datasets or large spreadsheets, Excel provides built-in tools and methods to help you identify and remove duplicates effectively. This guide will walk you throug
    9 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences