Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to merge two lists together, identify doubles, and delete them?

Hi,


Got a great solution for my last question, hope you guys can help me out on this one. As the title says, I have two lists in two separate Numbers documents. One is a selected amount of numbers in a column, where as the second one is a full amount. Lets use an example:


List in Numbers 1


Numbers 1

1

3
8
9
12

15


List in Numbers 2

Numbers 2

1

2
3
4

5

etc. all the way to 15


I want to copy the 15 values from Numbers 2, paste it in Numbers 1. Then sort everything from ascending to descending. I've been successful up to this part. Now I would like to remove all the identical values automatically. This where I am having issues.


I tried using this formula, which was found on another support page:

=IF(COUNTIF(OFFSET($A$1, 0, 0, ROW()-1), A)=0, "", "Dup")


But it didn't work it, it gave me an orange triangle and seemed to only find duplicates in the same row. I am trying to find duplicates in the same column. Here is the support page if interested:How to merge two list


I have to work with values in the thousands, so I hope we can find a way to find these duplicates. Thanks in advance.

MacBook Pro (Retina, 13-inch, Late 2012), OS X Yosemite (10.10.5), Numbers version 3.5.3 (2150)

Posted on Aug 25, 2015 3:44 PM

Reply
Question marked as Best reply

Posted on Aug 25, 2015 5:46 PM

To remove duplicates you may find it efficient to use this Copy Distinct Automator Service (Dropbox download).


To install just double-click the downloaded .workflow package and, if necessary, click "Install Anyway" in System Preferences > Security and Privacy.


To use:


  1. Select the cells with values containing duplicates.
  2. Choose Copy Distinct from the Numbers > Services menu.
  3. Click once in the top destination cell.
  4. Command-v to paste the "de-duplicated" values.


This is a lot quicker and easier than setting up complicated formulas and extra columns and tables each time you need to remove duplicates.


SG

6 replies
Question marked as Best reply

Aug 25, 2015 5:46 PM in response to underdog13

To remove duplicates you may find it efficient to use this Copy Distinct Automator Service (Dropbox download).


To install just double-click the downloaded .workflow package and, if necessary, click "Install Anyway" in System Preferences > Security and Privacy.


To use:


  1. Select the cells with values containing duplicates.
  2. Choose Copy Distinct from the Numbers > Services menu.
  3. Click once in the top destination cell.
  4. Command-v to paste the "de-duplicated" values.


This is a lot quicker and easier than setting up complicated formulas and extra columns and tables each time you need to remove duplicates.


SG

Aug 25, 2015 7:39 PM in response to underdog13

Here's a solution that does require the 'dreaded' extra column and a 'complicated' formula. 😉


Note that the initial data set in Numbers 1 is not sorted. It was created with a random number generator, and not re-ordered as the solution does not require that the initial set be in order.


Starting point:

Numbers 1 is the target table, containing the partial set of numbers.

Numbers 2 is the 'source' table, containing the full set, from which the numbers necessary to fill the set in Numbers 1 will be copied.

The added column B is used to determine which numbers need to be copied, then pasted into Numbers 1.


Enter the 'complicated' formula in cell B2, and fill down to the end of the column.

B2: =COUNTIF(Numbers 1 :: A,A)

With all of column B (except the top cell, which is in a Header row) selected, apply the following Conditional format rule to these cells:

User uploaded file

The tables will look like this:

User uploaded file

Step 1: Sort Numbers 2 on column B to gather all the 'needed' numbers into a group.

User uploaded file

Select the cells in column A that are on rows with zero in column B. Copy.

Click once on the first empty cell in Numbers 1. Paste.

User uploaded file

Note that column B of Numbers 2 gives you an immediate confirmation that there is one (and only one) copy of each number in column A of Numbers 1.

Finally, Sort column A of Numbers 1 in ascending order.

You may also want to re-sort Numbers 2 on the values in column A (which I haven't done in the 'final result' below).

User uploaded file

Regards,

Barry

Aug 26, 2015 7:23 AM in response to Barry

Compare and contrast all that to this:


Select the cells and choose 'Copy Distinct' from the Numbers > Services menu:


User uploaded file




Click once in a destination cell (I picked A2 in 'Table 1-1 here, but it could be anywhere, including the original table) and command-v to paste:


User uploaded file



'Sort Ascending' and you're done:


User uploaded file



That's it! All done in less than the time it takes to enter a formula and get it working.


No cleanup after you're finished, and and it's all ready to go for use the next time in another document.


SG




P.S. Meant to address this to Underdog13, not Barry. Barry's solution is the way to go with Numbers 2 as the 'Copy Distinct' service only works with Numbers 3.

Aug 26, 2015 12:29 PM in response to underdog13

Hello


The following simple perl script will get lines of text from the clipboard, extract the distinct lines, sort them in (lexiclally) ascending order and put the result in the clipboard, which you can paste as desired.



#!/bin/bash export LC_ALL=en_GB.UTF-8 # UTF-8 locale is required to let pbpaste and pbcopy handle UTF-8 text correctly perl -CSDA -w <<'EOF' - <(pbpaste) | pbcopy use strict; my %h = (); local $\ = qq(\n); while (<>) { chomp; $h{$_} = 1; } for (sort keys %h) { print $_; } EOF



For the current example, copy the cells in Table 3, run the script and paste (and match style) the result to Table 4.


User uploaded file




If you wish, you may create an Automator service to run the script. Service workflow consists of single Run Shell Script action as follows.


Service properties - Service receives [no input] in [any application] - [not checked] Replace selected text Run Shell Script action - Shell = /bin/bash - Pass input = as arguments - Code = as listed above



Resulting service workflow will look like this:


User uploaded file



If you wish, you may define keyboard shortcut for this service.


To use it, copy the source lines of text to the clipboard, invoke the service and paste the result to desired destination.



Regards,

H

How to merge two lists together, identify doubles, and delete them?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.