Delete duplicate rows of data in the R language

Source: Internet
Author: User

Duplicated

Description (description)

Duplicated () determines which elements of a vector or data frame is duplicates of elements with smaller subscripts, and R     Eturns a logical vector indicating which elements (rows) is duplicates. The duplicated () function is used to determine a vector or a repeating element of a data frame, subscript a smaller element, and returns a logical vector indicating which elements (rows) are duplicates.

So by default, the element with the lowest subscript is preserved, and if you want to keep the largest element, you can use the following statement:

table_dup<-table[!duplicated (table, fromlast=true),]
Fromlast is to keep the last row in the repeating row


Delete the same table_dup=table[!duplicated (table) as the data in all columns,]

Selective deletion of duplicate

Table_dup=test[!duplicated (Table[,c (2,3)),]//for an example


Unique

For a vector, it doesn't work for the matrix or data frame.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.