0
$\begingroup$

I want to create sublist from a big list in the way:

data = {{1., 0.18133, 0.18133}, {2., 0.148461, 0.148461}, {3., 0.121549, 0.121549},
 {4., 0.0995161, 0.0995161}, {5., 0.0814769, 0.0814769}, {1., 0.180988, 0.18133}, {2., 0.148243, 0.148461},
 {3., 0.121423, 0.121549}, {4., 0.0994543, 0.0995161}, {5., 0.0814604, 0.0814769}}

and I want to create sublists:

sub1 = {{1., 0.18133, 0.18133}, {2., 0.148461, 0.148461},
 {3., 0.121549, 0.121549}, {4., 0.0995161, 0.0995161}, {5., 0.0814769, 0.0814769}}

sub2 = {{1., 0.180988, 0.18133}, {2., 0.148243, 0.148461},
 {3., 0.121423, 0.121549}, {4., 0.0994543, 0.0995161}, {5., 0.0814604, 0.0814769}}

and so on, in order to manipulate each list separately. Until now I used: Take[data, n] and Partition[data, n] but I can not use the sublist in an independent way.

$\endgroup$
1
  • 1
    $\begingroup$ Please supply real data the people could experiment with, not some vague abbreviated form. Also supply a clear example of what the result should be. $\endgroup$ – m_goldberg Nov 26 '16 at 0:18
1
$\begingroup$
data = {{1., 0.18133, 0.18133}, {2., 0.148461, 0.148461}, {3., 
    0.121549, 0.121549}, {4., 0.0995161, 0.0995161}, {5., 0.0814769, 
    0.0814769}, {1., 0.180988, 0.18133}, {2., 0.148243, 
    0.148461}, {3., 0.121423, 0.121549}, {4., 0.0994543, 
    0.0995161}, {5., 0.0814604, 0.0814769}};

Evaluate@ToExpression@
   Table["sub" <> ToString@i, {i, Length@Partition[data, 5]}] = 
 Partition[data, 5];

Then

sub1

{{1., 0.18133, 0.18133}, {2., 0.148461, 0.148461}, {3., 0.121549, 0.121549}, {4., 0.0995161, 0.0995161}, {5., 0.0814769, 0.0814769}}

sub2

{{1., 0.180988, 0.18133}, {2., 0.148243, 0.148461}, {3., 0.121423, 0.121549}, {4., 0.0994543, 0.0995161}, {5., 0.0814604, 0.0814769}}


Or just simply

sub = Partition[data, 5];

and you can refer to sublists of sub via Part:

sub[[1]]
sub[[2]]
$\endgroup$
1
$\begingroup$
data = {{{1, 0.1}, {2, 0.2}, {n, m}}, {{1, 0.1}, {2, 0.2}, {n, m}}}
Table[Evaluate[ToExpression["sub" <> ToString@i]] = data[[i]], {i, 1, Length[data]}]

sub1
(*Out[]={{1, 0.1}, {2, 0.2}, {n, m}}*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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