Questions tagged [duplicates]

The "duplicates" tag concerns detecting and/or dealing with multiple instances of items in collections.

A duplicate is any re-occurrence of an item in a collection. This can be as simple as two identical strings in a list of strings, or multiple complex objects which are treated as the same object when compared to each other.

This tag may pertain to questions about preventing, detecting, removing, or otherwise dealing with unwanted duplicates, or adapting to safely allow duplicates.

15777 questions
218
votes
10 answers

Remove duplicated rows

I have read a CSV file into an R data.frame. Some of the rows have the same element in one of the columns. I would like to remove rows that are duplicates in that column. For example: platform_external_dbus 202 16 …
user1897691
  • 2,331
  • 3
  • 14
  • 12
207
votes
5 answers

How to merge 2 List and removing duplicate values from it in C#

I have two lists List that I need to combine in third list and remove duplicate values from that lists A bit hard to explain, so let me show an example of what the code looks like and what I want as a result, in sample I use int type not…
Kiquenet
  • 14,494
  • 35
  • 148
  • 243
198
votes
24 answers

Removing duplicate rows from table in Oracle

I'm testing something in Oracle and populated a table with some sample data, but in the process I accidentally loaded duplicate records, so now I can't create a primary key using some of the columns. How can I delete all duplicate rows and leave…
juan
  • 80,295
  • 52
  • 162
  • 195
193
votes
26 answers

In MySQL, can I copy one row to insert into the same table?

insert into table select * from table where primarykey=1 I just want to copy one row to insert into the same table (i.e., I want to duplicate an existing row in the table) but I want to do this without having to list all the columns after the…
lina
  • 1,931
  • 2
  • 12
  • 4
186
votes
8 answers

How to "select distinct" across multiple data frame columns in pandas?

I'm looking for a way to do the equivalent to the SQL SELECT DISTINCT col1, col2 FROM dataframe_table The pandas sql comparison doesn't have anything about distinct. .unique() only works for a single column, so I suppose I could concat the…
Jody
  • 8,021
  • 4
  • 26
  • 29
183
votes
9 answers

How to get duplicate items from a list using LINQ?

I'm having a List like: List list = new List{"6","1","2","4","6","5","1"}; I need to get the duplicate items in the list into a new list. Now I'm using a nested for loop to do this. The resulting list will contain…
Thorin Oakenshield
  • 14,232
  • 33
  • 106
  • 146
172
votes
11 answers

How do I remove duplicate items from an array in Perl?

I have an array in Perl: my @my_array = ("one","two","three","two","three"); How do I remove the duplicates from the array?
David
  • 14,047
  • 24
  • 80
  • 101
172
votes
25 answers

How to delete duplicates on a MySQL table?

I need to DELETE duplicated rows for specified sid on a MySQL table. How can I do this with an SQL query? DELETE (DUPLICATED TITLES) FROM table WHERE SID = "1" Something like this, but I don't know how to do it.
Ali Demirci
  • 5,302
  • 7
  • 39
  • 66
171
votes
17 answers

Regular expression for duplicate words

I'm a regular expression newbie and I can't quite figure out how to write a single regular expression that would "match" any duplicate consecutive words such as: Paris in the the spring. Not that that is related. Why are you laughing? Are my my…
Joshua
  • 6,643
  • 15
  • 55
  • 76
160
votes
9 answers

Finding ALL duplicate rows, including "elements with smaller subscripts"

R's duplicated returns a vector showing whether each element of a vector or data frame is a duplicate of an element with a smaller subscript. So if rows 3, 4, and 5 of a 5-row data frame are the same, duplicated will give me the vector FALSE,…
Lauren Samuels
  • 2,419
  • 3
  • 19
  • 20
158
votes
9 answers

Does adding a duplicate value to a HashSet/HashMap replace the previous value

Please consider the below piece of code: HashSet hs = new HashSet(); hs.add("hi"); -- (1) hs.add("hi"); -- (2) hs.size() will give 1 as HashSet doesn't allow duplicates so only one element will be stored. I want to know if we add the duplicate…
Anand
  • 20,708
  • 48
  • 131
  • 198
157
votes
14 answers

Removing duplicate rows in vi?

I have a text file that contains a long list of entries (one on each line). Some of these are duplicates, and I would like to know if it is possible (and if so, how) to remove any duplicates. I am interested in doing this from within vi/vim, if…
Sydius
  • 13,567
  • 17
  • 59
  • 76
154
votes
11 answers

In Javascript, how do I check if an array has duplicate values?

Possible Duplicate: Easiest way to find duplicate values in a javascript array How do I check if an array has duplicate values? If some elements in the array are the same, then return true. Otherwise, return false. ['hello','goodbye','hey']…
user847495
  • 9,831
  • 17
  • 45
  • 48
142
votes
8 answers

Linux command or script counting duplicated lines in a text file?

If I have a text file with the following conent red apple green apple green apple orange orange orange Is there a Linux command or script that I can use to get the following result? 1 red apple 2 green apple 3 orange
timeon
  • 2,194
  • 4
  • 18
  • 19
138
votes
10 answers

How do I find duplicates across multiple columns?

So I want to do something like this sql code below: select s.id, s.name,s.city from stuff s group by s.name having count(where city and name are identical) > 1 To produce the following, (but ignore where only name or only city match, it has to be…
NimChimpsky
  • 46,453
  • 60
  • 198
  • 311