2
$\begingroup$

New to Mathematica, just have a very basic question to ask. I have a table of results like so:

{{4.,{14.4979,17.8394}},{5.,{16.0066,17.7698}},{6.,{18.1552,18.0112}},{7.,{20.5851,18.5351}},{8.,{23.0556,19.2772}},{9.,{25.39,20.1617}},{10.,{27.4519,21.1124}},{11.,{29.1339,22.058}},{12.,{30.354,22.9347}},{13.,{31.0536,23.6877}},{14.,{31.1983,24.2718}},{15.,{30.7772,24.6525}},{16.,{29.8025,24.8062}},{17.,{28.3091,24.72}},{18.,{26.3525,24.3922}},{19.,{24.0063,23.8318}},{20.,{21.3596,23.0574}}}

I would like to select the second element of the nested list to obtain:

{{8.01854, 12.5027}, {10.1469, 12.589}, {12.1229, 12.9617}, {13.9934, 13.5151}, {15.7178, 14.1746}, {17.2352, 14.8803}, {18.4861, 15.5813}, {19.4205, 16.2338}, {20.0002, 16.8009}, {20.2014, 17.2522}, {20.0153, 17.5641}, {19.4481, 17.7204}, {18.5211, 17.7118}, {17.2693, 17.5364}, {15.7405, 17.1994}, {13.9934, 16.7124}, {12.0948, 16.0934}}

And then the first and second elements of the above list to form two separate lists:

{8.01854, 10.1469, 12.1229, 13.9934, 15.7178, 17.2352, 18.4861, 19.4205, 20.0002, 20.2014, 20.0153, 19.4481, 18.5211, 17.2693, 15.7405, 13.9934, 12.0948}

{12.5027, 12.589, 12.9617, 13.5151, 14.1746, 14.8803, 15.5813, 16.2338, 16.8009, 17.2522, 17.5641, 17.7204, 17.7118, 17.5364, 17.1994, 16.7124, 16.0934}

I know how to do this by using the command prompts, but need to code this in so the lists are attached to two separate variables. Any help greatly appreciated!

$\endgroup$

closed as off-topic by xyz, Yves Klett, rcollyer, Bob Hanlon, dr.blochwave Jul 14 '15 at 14:25

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." – xyz, Yves Klett, rcollyer, Bob Hanlon, dr.blochwave
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Try data[[All, 2]] and data[[All, 2]][[All, 1]] $\endgroup$ – Enrique Pérez Herrero Jul 14 '15 at 13:09
  • $\begingroup$ @Fraser the first list does not seem to relate to the second (and subsequent) list $\endgroup$ – ubpdqn Jul 14 '15 at 13:15
  • $\begingroup$ Just figured it out! So easy - thanks for the reply! $\endgroup$ – Fraser Jul 14 '15 at 13:15
  • 1
    $\begingroup$ For the single components you can extend Fraser's answer to data[[All, 2, 1]] and data[[All, 2, 2]]. The answers are not sorted as you show. If you want that you can wrap it in Sort[data[[All,2,1]]. $\endgroup$ – Jack LaVigne Jul 14 '15 at 13:16
  • $\begingroup$ You can do {list1,list2}=Transpose@data[[All,2]] $\endgroup$ – N.J.Evans Jul 14 '15 at 14:19

Browse other questions tagged or ask your own question.