-1
$\begingroup$

This is sample data

data = {{1, 1, 1, 1, 1, 1}, {2, 2, 2, 2, 2, 2}, {3, 3, 3, 3, 3, 3}, 
       {5, 5, 5, 5, 5, 5}, {6, 6, 6, 6, 6, 6}}

My actual data contains 10000 sub-lists with 6 elements.

How can I create a new list data2 containing a sample of N random six-lets of the initial list?

In our MWE let's take N = 3.

Many thanks in advance!

$\endgroup$

closed as off-topic by Dr. belisarius, Michael E2, Daniel Lichtblau, dr.blochwave, user9660 Nov 26 '15 at 19:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Dr. belisarius, Michael E2, Daniel Lichtblau, dr.blochwave, Community
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    $\begingroup$ RandomSample[data, 3] I believe you have to practice your docs-fu $\endgroup$ – Dr. belisarius Nov 26 '15 at 17:47
  • $\begingroup$ @belisariushassettled With your suggestion is there a chance a six-let to appear twice or more times in the new list, or all N are different? $\endgroup$ – Vaggelis_Z Nov 26 '15 at 17:52
  • 4
    $\begingroup$ Dude, don't ask those things. Go to the docs and check them out $\endgroup$ – Dr. belisarius Nov 26 '15 at 17:54
  • $\begingroup$ @belisariushassettled You are right! Some times I so lazy... $\endgroup$ – Vaggelis_Z Nov 26 '15 at 18:02
4
$\begingroup$

If I understood well, you do not want to create those sample elements out of the elements of sublists. With this assumption the answer is

n=3;
data2=RandomChoice[data, n]

Example output:

{{3, 3, 3, 3, 3, 3}, {2, 2, 2, 2, 2, 2}, {2, 2, 2, 2, 2, 2}}

If you would like to randomly select out of all elements it would be:

data2=RandomChoice[Flatten@data, {n, 6}]

Example output:

{{2, 6, 1, 5, 3, 1}, {6, 1, 5, 2, 1, 6}, {3, 3, 6, 2, 2, 1}}

EDIT: If no elements are supposed to repeat then it would be:

data2=RandomSample[data, n]

Example output:

{{2, 2, 2, 2, 2, 2}, {5, 5, 5, 5, 5, 5}, {3, 3, 3, 3, 3, 3}}
$\endgroup$
  • $\begingroup$ No, I want N random six-lets from the initial data. But all of them should be different. In your suggestion the six-let (2,2,2,2,2,2) appears twice! $\endgroup$ – Vaggelis_Z Nov 26 '15 at 17:50
  • $\begingroup$ The last one is really what I want! $\endgroup$ – Vaggelis_Z Nov 26 '15 at 17:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.