# Create sublists of x, y pairs for multiple y-coordinates

I have a matrix data in which column 5 holds x-coordinates, and then columns 6 through 37 each holds sets of y-coordinates. I want to map x, y pairs, keeping the pairs separated according to each set of y-coordinates. This would form a nested structure like this:

{...
{{1., 1812.}, {2., 10076.}, {3., 4764}},
{{1., 6839.}, {2., 3849.}, {3., 2746}},
{{1., 6839.}, {2., 3849.}, {3., 2746}}
...}


where the first sublist holds x, y pairs for column 5, the second sublist holds x, y pairs for column 6, and so on until column 37.

I've managed to get x, y pairs for the first set of y-coordinates:

Transpose[{data[[All, 5]], data[[All, 6]]}]

This gives me

{{1., 1812.}, {2., 10076.}, {3., 4764.}}


How can I also get x, y pairs for the remaining sets of y-coordinates?

• Is the x-coordinates column duplicate-free?
– kglr
Jul 7, 2018 at 21:58
• Not in my dataset, no. I happen to have repeating x-coordinates of 1, 2, 3, all with corresponding y-values. I truncated it here. @kglr Jul 7, 2018 at 22:04

If your data structure is as presented, then I believe the following should work:

Inner[List, data[[All, 5]], data[[All, 6 ;; 37]], List]


Inner is a very powerful function for manipulating rectangular data structures, would recommend looking into its use. To understand what's actually going on here, I'd recommend starting with:

Inner[f, data[[All, 5]], data[[All, 6 ;; 37]], g]


Assuming that f and g are undefined.

• @briennakh Made a change after taking a closer look at the data structure. It looks like it should work now. Jul 7, 2018 at 21:01
• It works! Thanks! It's good to know about Inner Jul 7, 2018 at 21:05