Data Sampling, random but consecutive

kirkley08

New Member
Joined
Mar 29, 2023
Messages
20
Office Version
  1. 2021
  2. 2019
  3. 2016
Platform
  1. Windows
Hi all, so I have this big data that I need to check by taking sample randomly, but I want the sample data to be somehow consecutive, like consecutive 4 data from any number/row I choose.

For example I have 200 datas and I need to take and check 20 samples out of them, I want the samples to be present in the next column like data 3 to 6 (4 samples), data 20 to 24 (4 samples), 86 to 89, 111 to 115 and lastly 169 to 172.

So the number 3, 20, 86, 111 and 169 is chosen randomly, but will be the starting number of the next 3 samples, if that makes sense.

Thank you!
 

Attachments

  • sampling.jpg
    sampling.jpg
    66.1 KB · Views: 7

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You need starting positions between 1 and 197 (since starting at 197 will include data points up to 200).
In cells B1 to B5, enter the following formula to generate random integers:
=RANDBETWEEN(1,197)
This will give you 5 random starting positions.

In cell C1, extract the first data point using:

=INDEX($A$1:$A$200, $B1)

In cell D1:

=INDEX($A$1:$A$200, $B1+1)

In cell E1:

=INDEX($A$1:$A$200, $B1+2)

In cell F1:

=INDEX($A$1:$A$200, $B1+3)
 
Upvote 0
To take the answer above a step further in case you don't fully follow it. This is how you can put it into practice for what you need.

Cell Formulas
RangeFormula
D2D2=RANDBETWEEN(2,D1*10-3)
E2:W2E2=RANDBETWEEN(D1*10,E1*10-3)
D3:W3D3=INDEX($A$1:$A$200, D2)
D4:W4D4=INDEX($A$1:$A$200, D2+1)
D5:W5D5=INDEX($A$1:$A$200, D2+2)
D6:W6D6=INDEX($A$1:$A$200, D2+3)
 
Upvote 0
Thank you for both of you!
I tried it just now and it works!
 
Upvote 0
I tried it just now and it works!
That depends on how particular you are and how random you want the results to be.

The post 2 suggestion can lead to data being repeated. Here is an example that came up for me using that suggestion.

kirkley08.xlsm
ABCDEF
1645ABC1855ABC1865ABC1875ABC188
25ABC123705ABC1915ABC1925ABC1935ABC194
35ABC1241795ABC3005ABC3015ABC3025ABC303
45ABC125695ABC1905ABC1915ABC1925ABC193
55ABC126585ABC1795ABC1805ABC1815ABC182
65ABC127
75ABC128
85ABC129
95ABC130
105ABC131
115ABC132
Sheet1
Cell Formulas
RangeFormula
B1:B5B1=RANDBETWEEN(1,197)
C1:C5C1=INDEX($A$1:$A$200, $B1)
D1:D5D1=INDEX($A$1:$A$200, $B1+1)
E1:E5E1=INDEX($A$1:$A$200, $B1+2)
F1:F5F1=INDEX($A$1:$A$200, $B1+3)


Unless I am misunderstanding how it is supposed to be interpreted, the post 3 suggestion can also contain repeats. Here is an example that came up for me using that suggestion.

kirkley08.xlsm
ABCDEFG
1DataNumber1234
25AB102RNG #3172036
35AB103sample 15AB1035AB1175AB1205AB136
45AB104sample 25AB1045AB1185AB1215AB137
55AB105sample 35AB1055AB1195AB1225AB138
65AB106sample 45AB1065AB1205AB1235AB139
75AB107
85AB108
95AB109
105AB110
115AB111
Sheet3
Cell Formulas
RangeFormula
D2D2=RANDBETWEEN(2,D1*10-3)
E2:G2E2=RANDBETWEEN(D1*10,E1*10-3)
D3:G3D3=INDEX($A$1:$A$200, D2)
D4:G4D4=INDEX($A$1:$A$200,D2+1)
D5:G5D5=INDEX($A$1:$A$200,D2+2)
D6:G6D6=INDEX($A$1:$A$200,D2+3)


Also, the post 3 suggestion will not produce truly random samples. For example, if truly random, it would be possible that at some stage the data from, say, A2:A5 could be in the sample and the data from, say, A7:A10 could also be part of the random sample. That combination would never be possible with the post 3 suggestion.
 
Upvote 0
Ahh yeah, now that you mention it I found that bug too. I tried adding RANK formula in the INDEX formula from post 2 hoping that I won't get duplicate results, well there are still some duplicates but not as frequent as previous one (or maybe my understanding of RANK formula is wrong?).
 
Upvote 0

Forum statistics

Threads
1,222,902
Messages
6,168,938
Members
452,227
Latest member
sam1121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top