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:
Remove Objects from Memory in R Programming - rm() Function
Next article icon

Remove Duplicate Elements from an Object in R Programming – unique() Function

Last Updated : 04 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

unique() function in R Language is used to remove duplicated elements/rows from a vector, data frame or array.

Syntax: unique(x)

Parameters:
x: vector, data frame, array or NULL

Example 1:




# R program to illustrate
# unique function
   
# Initializing some set of numbers
x <- c(1:10, 5:9)
x
  
# Calling unique() function to print
# unique set of numbers
unique(x)
 
 

Output:

  [1]  1  2  3  4  5  6  7  8  9 10  5  6  7  8  9  [1]  1  2  3  4  5  6  7  8  9 10  

Example 2:




# R program to illustrate
# unique function
    
# Initializing a matrix
x <- matrix(rep(1:9, length.out = 18), 
            nrow = 6, ncol = 3, byrow = T)
x
   
# Calling unique() function to print
# unique set of numbers in the matrix
unique(x)
 
 

Output:

       [, 1] [, 2] [, 3]  [1, ]    1    2    3  [2, ]    4    5    6  [3, ]    7    8    9  [4, ]    1    2    3  [5, ]    4    5    6  [6, ]    7    8    9         [, 1] [, 2] [, 3]  [1, ]    1    2    3  [2, ]    4    5    6  [3, ]    7    8    9  


Next Article
Remove Objects from Memory in R Programming - rm() Function

K

Kanchan_Ray
Improve
Article Tags :
  • R Language
  • R DataFrame-Function
  • R Matrix-Function
  • R Object-Function
  • R Vector-Function

Similar Reads

  • Remove names or dimnames from an Object in R Programming - unname() Function
    unname() function in R Language is used to remove the names or dimnames from an Object. Syntax: unname(x) Parameters: x: Object Example 1: # R Program to remove names from an object # Creating a matrix A = matrix(c(1:9), 3, 3) # Naming rows rownames(A) = c("a", "b", "c"
    1 min read
  • Seeking a unique match of elements in R Programming - char.expand() Function
    char.expand() function in R Language is used to seek a unique match of its first argument among the elements of its second. If successful, it returns this element; otherwise, it performs an action specified by the third argument.  Syntax: char.expand(input, target, nomatch = stop("no match"))Paramet
    1 min read
  • Removing Levels from a Factor in R Programming - droplevels() Function
    droplevels() function in R programming used to remove unused levels from a Factor. Syntax: # For vector object droplevels(x, exclude = if(anyNA(levels(x))) NULL else NA, ...) # For data frame object droplevels(x, except, exclude) Parameter values: x represents object from which unused level has to b
    2 min read
  • Remove Objects from Memory in R Programming - rm() Function
    rm() function in R Language is used to delete objects from the memory. It can be used with ls() function to delete all objects. remove() function is also similar to rm() function. Syntax: rm(x) Parameters: x: Object name Example 1: # R Program to remove # objects from Memory # Creating a vector vec
    2 min read
  • Convert an Object to Data Frame in R Programming - as.data.frame() Function
    as.data.frame() function in R Programming Language is used to convert an object to data frame. These objects can be Vectors, Lists, Matrices, and Factors. Syntax: as.data.frame(object) Parameters:  object: Vector, Matrix, factor, or data frameR - as.data.frame() Function ExampleExample 1: Basic exam
    2 min read
  • Make Elements of a Vector Unique in R Programming - make.unique() Function
    make.unique() function in R Language is used to return elements of a vector with unique names by appending sequence numbers to duplicates. Syntax: make.unique(names, sep)Parameters: names: Character vector with duplicate names sep: Separator to be used   Example 1:  [GFGTABS] Python3 # R program to
    1 min read
  • Create Subsets of a Data frame in R Programming - subset() Function
    subset() function in R Programming Language is used to create subsets of a Data frame. This can also be used to drop columns from a data frame. Syntax: subset(df, expr) Parameters: df: Data frame usedexpr: Condition for subsetCreate Subsets of Data Frames in R Programming LanguageHere we will make s
    3 min read
  • Get the Minimum element of an Object in R Programming - min() Function
    min() function in R Language is used to find the minimum element present in an object. This object can be a Vector, a list, a matrix, a data frame, etc.. Syntax: min(object, na.rm) Parameters: object: Vector, matrix, list, data frame, etc. na.rm: Boolean value to remove NA element. Example 1: # R pr
    1 min read
  • Get the Maximum element of an Object in R Programming - max() Function
    max() function in R Language is used to find the maximum element present in an object. This object can be a Vector, a list, a matrix, a data frame, etc.. Syntax: max(object, na.rm) Parameters: object: Vector, matrix, list, data frame, etc. na.rm: Boolean value to remove NA element. Example 1: # R pr
    1 min read
  • Check if Two Objects are Equal in R Programming - setequal() Function
    setequal() function in R Language is used to check if two objects are equal. This function takes two objects like Vectors, dataframes, etc. as arguments and results in TRUE or FALSE, if the Objects are equal or not. Syntax: setequal(x, y) Parameters: x and y: Objects with sequence of items Example 1
    1 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