+ Reply to Thread
Results 1 to 10 of 10

Random sample in excel WITHOUT duplicates.

Hybrid View

  1. #1
    Registered User
    Join Date
    06-10-2009
    Location
    Austin, TX
    MS-Off Ver
    Professional Plus 2010
    Posts
    21

    Random sample in excel WITHOUT duplicates.

    Hello everyone,

    I have had too many of my excel troubles solved by the good members of this thread so I feel compelled to contribute my accidental excel accomplishment for which I could not find a solution online (sorry, if I just missed it) - obtaining random samples in excel without duplicates.

    The purpose of the attached file is to obtain a true random sample of unique results from any data population of size N. This can’t be done in Excel’s data analysis tool-pack (Data tab > Data Analysis > Random number generation) because in that output, values can be repeated in sample extract of sufficient size proportional to total population, i.e., duplicates appear in random sample.

    This file is set to work for a data population of 28 comprising of 26 letters of the English alphabet and 2 intentionally inserted duplicates (letters J and Q) to prove that duplicates will not be included in random sample obtained and that the formulas work as intended. Therefore, the maximum number of unique results that can be obtained in a random sample is 26 (28 letters – 2 duplicates).

    1. To refresh random samples of size n=1 to n=26, press F9.

    2. To use this file for a larger population:

    a. Insert lines as needed below index value 2 since formulas are different for row containing index value 1
    b. Copy your selection criteria (names, numbers etc.) in column B
    c. Copy formulas down in lines inserted.
    d. Make sure numbers in column A are in sequential order.

    3. To obtain a sample size larger than 26, simply enter the desired size in row 1 of any column and delete the remaining sample columns.

    I hope you’d find this file useful. Your comments / corrections are welcome!

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,355

    Re: Random sample in excel WITHOUT duplicates.

    Hi rshukla,

    I'm not exactly sure what the question is but it seems to me there is another way. If you want a random sample without duplicates, like dealing a deck of cards, you simply need a helping column. This column has a random number in each row, next to the card. You F9 to reset all the random numbers and then sort by this column. If you want 15 of the 52 cards you simply take the top 15 rows as your answer.

    This is how I've done random without repeats in the past. Does your solution do more than this?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    06-10-2009
    Location
    Austin, TX
    MS-Off Ver
    Professional Plus 2010
    Posts
    21

    Re: Random sample in excel WITHOUT duplicates.

    Hi Marvin,

    For 'a' deck of cards, your method will work. However, what if your population comprised of 10 similar decks of cards and you wanted to choose 52 unique values? This is where the method you described has a shortcoming - it will give you a random sample of 52 cards, but it will inevitably comprise of some duplicate cards.

    For statistical sampling, presence of duplicates is not always desired and sometimes not to have duplicates is an explicit requirement. That's what my file attempts to do - remove duplicates, if present, in a random sample extraction.

    Thanks!

  4. #4
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    365
    Posts
    2,243

    Re: Random sample in excel WITHOUT duplicates.

    Hi Shukla,

    I am not sure i fully understand you. If you want the unique values in column G, this should work

    In G3, with CTRL+SHIFT+ENTER, then copy down.

    =IFERROR(INDEX(F$3:F$30,MATCH(TRUE,ISNA(MATCH(F$3:F$30,G$2:G2,0)),0)),"")
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  5. #5
    Registered User
    Join Date
    06-10-2009
    Location
    Austin, TX
    MS-Off Ver
    Professional Plus 2010
    Posts
    21

    Re: Random sample in excel WITHOUT duplicates.

    Hi Haseeb / Martin,

    I haven't tried your formulae yet but I believe you both and it very well may work. I just tried to solve the problem step-by-step using formulas I know and it worked. I'm sure there are other ways as well, but I was just happy to be able to solve it somehow.

    Thanks for the formulae you posted!
    Last edited by rshukla; 05-27-2012 at 08:59 PM.

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Random sample in excel WITHOUT duplicates.

    i think you can reduce all that to this i limited the range to 50 but you can make it bigger
    you could take a chance and not rank unique but rand() can produce duplicates
    Attached Files Attached Files
    Last edited by martindwilson; 05-27-2012 at 08:43 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  7. #7
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Random sample in excel WITHOUT duplicates.

    i dont know what hasseb is suggesting that array for its not giving random anything, i suppose you could use it to get a list to choose from but as you are already down the helper column route i see little gain , see improved version attached up to 500 entries ,try going above the number of unique items
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    06-10-2009
    Location
    Austin, TX
    MS-Off Ver
    Professional Plus 2010
    Posts
    21

    Re: Random sample in excel WITHOUT duplicates.

    Martin,

    Interesting that you pointed out that "Rand()" can produce duplicates. My solution was to increase the decimal places (x.xxxxxxxxxx...xxx instead of just x.xx) but it helps me to have a formula that would avoid this (remote) possibility. Although, it will take me some time to decipher what you've done there...

    Thanks!

  9. #9
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Random sample in excel WITHOUT duplicates.

    well i'm being paranoid because as rand() gives a 15 place decimal it is extremely unlikely. btw increasing or decreasing decimal places has no effect the value is still the same you just cant see it all.

  10. #10
    Registered User
    Join Date
    08-09-2017
    Location
    Manila, Philippines
    MS-Off Ver
    2013
    Posts
    1

    Re: Random sample in excel WITHOUT duplicates.

    found another way to generate random numbers without duplicates
    let the first cell be a heading e.g in A1 =Random Generated
    have the second cell like this e.g in A2 =RandBetween(1,20)
    the third cell like this e.g in A3 =LARGE(ROW($1:$20)*NOT(COUNTIF($A$2:A2,ROW($1:$20))),RANDBETWEEN(1,(20+2-1)-ROW(A2)))
    press CTRL + SHIFT + ENTER
    copy paste to the next row until the desired number of samples were generated.


    TAKE NOTE OF THE $ SIGN AND CTRL + SHIFT + ENTER
    ALSO, THE NUMBERS 1 AND 20 COULD BE CHANGED DEPENDING UPON THE NUMBER OF POPULATION

    :D

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1