How to Remove Duplicate Rows in R DataFrame? Last Updated : 15 Feb, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to remove duplicate rows in dataframe in R programming language. Dataset in use:Method 1: Using distinct() This method is available in dplyr package which is used to get the unique rows from the dataframe. We can remove rows from the entire which are duplicates and also we cab remove duplicate rows in a particular column. Syntax: distinct(dataframe) distinct(dataframe,column1,column2,.,column n) Example: R program to remove duplicate rows using distinct() function R # load the package library(dplyr) # create dataframe data=data.frame(names=c("manoj","bobby","sravan", "deepu","manoj","bobby") , id=c(1,2,3,4,1,2), subjects=c("java","python","php", "html","java","python")) # remove all duplicate rows print(distinct(data)) # remove duplicate rows in subjects column print(distinct(data,subjects)) # remove duplicate rows in namescolumn print(distinct(data,names)) Output: Method 2: Using duplicated() This function will return the duplicates from the dataframe, In order to get the unique rows, we have to specify ! operator before this method Syntax: data[!duplicated(data$column_name), ] where, data is the input dataframecolumn_name is the column where duplicates are removed in this column Example: R program to remove duplicate rows using duplicated() function R # create dataframe data=data.frame(names=c("manoj","bobby","sravan", "deepu","manoj","bobby") , id=c(1,2,3,4,1,2), subjects=c("java","python","php", "html","java","python")) # remove duplicate rows in subjects column print(data[!duplicated(data$subjects), ]) # remove duplicate rows in names column print(data[!duplicated(data$names), ]) # remove duplicate rows in id column print(data[!duplicated(data$id), ]) Output: Method 3 : Using unique() This will get the unique rows from the dataframe. Syntax: unique(dataframe) To get in a particular column Syntax: unique(dataframe$column_name Example: R program to remove duplicate rows using unique() function R # create dataframe data=data.frame(names=c("manoj","bobby","sravan", "deepu","manoj","bobby") , id=c(1,2,3,4,1,2), subjects=c("java","python","php", "html","java","python")) # remove duplicate rows in subjects column print(unique(data$subjects)) # remove duplicate rows in names column print(unique(data$names)) # remove duplicate rows in id column print(unique(data$id)) Output: [1] "java" "python" "php" "html" [1] "manoj" "bobby" "sravan" "deepu" [1] 1 2 3 4 Example: R program to apply unique() function in entire dataframe R # create dataframe data=data.frame(names=c("manoj","bobby","sravan", "deepu","manoj","bobby") , id=c(1,2,3,4,1,2), subjects=c("java","python","php", "html","java","python")) # remove duplicate rows in entire dataframe print(unique(data)) Output: Comment More infoAdvertise with us Next Article How to Remove Duplicate Rows in R DataFrame? M manojkumarreddymallidi Follow Improve Article Tags : R Language R Programs R-DataFrame R DataFrame-Programs Similar Reads How to Remove Rows in R DataFrame? In this article, we will discuss how to remove rows from dataframe in the R programming language. Method 1: Remove Rows by Number By using a particular row index number we can remove the rows. Syntax: data[-c(row_number), ] where. data is the input dataframerow_number is the row index position Exam 2 min read How to Delete Row(s) in R DataFrame ? In this article, we will see how row(s) can be deleted from a Dataframe in R Programming Language. Deleting a single row For this, the index of the row to be deleted is passed with a minus sign. Syntax: df[-(index), ] Example 1 : R # creating a data frame with # some data . df=data.frame(id=c(1,2,3 2 min read How to remove empty rows from R dataframe? A dataframe can contain empty rows and here with empty rows we don't mean NA, NaN or 0, it literally means empty with absolutely no data. Such rows are obviously wasting space and making data frame unnecessarily large. This article will discuss how can this be done. To remove rows with empty cells w 1 min read Remove First Row of DataFrame in R In this article, we are going to see how to remove the first row from the dataframe. We can remove first row by indexing the dataframe. Syntax: data[-1,] where -1 is used to remove the first row which is in row position Example 1: R program to create a dataframe with 2 columns and delete the first 1 min read How to Conditionally Remove Rows in R DataFrame? In this article, we will discuss how to conditionally remove rows from a dataframe in the R Programming Language. We need to remove some rows of data from the dataframe conditionally to prepare the data. For that, we use logical conditions on the basis of which data that doesn't follow the condition 4 min read How to remove a subset from a DataFrame in R ? A subset is a combination of cells that form a smaller data frame formed out from the original data frame. A set of rows and columns can be removed from the original data frame to reduce a part of the data frame. The subset removal can be based on constraints to which rows and columns are subjected 4 min read How to Retrieve Row Numbers in R DataFrame? In this article, we will discuss how to Retrieve Row Numbers in R Programming Language. The dataframe column can be referenced using the $ symbol, which finds its usage as data-frame$col-name. The which() method is then used to retrieve the row number corresponding to the true condition of the speci 2 min read Remove rows with NA in one column of R DataFrame Columns of DataFrame in R Programming Language can have empty values represented by NA. In this article, we are going to see how to remove rows with NA in one column. We will see various approaches to remove rows with NA values.ApproachCreate a data frameSelect the column based on which rows are to 2 min read How to add dataframe to dataframe in R ? In this article, we will see how to add dataframe at the end of another dataframe in R Programming Language. Method 1: Using rbind() method The rbind() method in R works only if both the input dataframe contains the same columns with similar lengths and names. The dataframes may have a different num 4 min read How to Remove Rows with Some or All NAs in R DataFrame? In this article, we will discuss how to remove rows with some or all NA's in R Programming Language. We will consider a dataframe and then remove rows in R. Let's create a dataframe with 3 columns and 6 rows. R # create dataframe data = data.frame(names=c("manoj", "bobby", "sravan", "deepu", NA, NA) 2 min read Like