How to construct a dataset with lists as columns

So I know this should be pretty easy, but I cannot seem to find a solution anywhere, so thanks in advance for your help: I have three Lists (with numbers as elements) named lista, listb and listc and I want to construct adataset with columns "a" to "c", where column "a" contains all elements from "lista" and so on. I then want to be able to use the data in other dataset operations (like Select or LinearModelFit etc.). And, while I don't know if it makes a difference, each list has 1000 elements and all lists are therefore equally long. Thanks again for inputs!

• Welcome to MSE! Assuming your lists are the same length you can do data=Transpose[{lista,list,listc}] and the proceed as you desire. Try things for yourself. If you get into trouble then you can seek help. Ideally, a minimal working example makes it easier for responders (and may even provide you your own insight). :) – ubpdqn Apr 4 '16 at 9:49

Let's take some example lists:

lis1 = {1, 2, 3, 4, 5};
lis2 = {6, 7, 8, 9, 0};
lis3 = {2, 4, 6, 8, 9};


data = {lis1, lis2, lis3};


To create a dataset just do:

Dataset@Map[AssociationThread[header, #] &]@Transpose[data]


• I didn't know about AssociationThread, was trying to make it up from scratch like Association @@@ Transpose[ {Thread["a" -> lista], Thread["b" -> listb], Thread["c" -> listc]}] This is better – Jason B. Apr 4 '16 at 9:55
• @JasonB, Yeah, it's a nice little function that makes life easier :) – RunnyKine Apr 4 '16 at 9:57
• +1).Rarely to use Map like this. – yode Apr 4 '16 at 15:31
• @yode, Thanks. Yeah, the operator form is nice sometimes. – RunnyKine Apr 4 '16 at 21:56

If using Mathematica version 10.1 or later, we can write:

lista = {1, 2, 3, 4, 5};
listb = {6, 7, 8, 9, 0};
listc = {2, 4, 6, 8, 9};

<| "a" -> lista, "b" -> listb, "c" -> listc |> // Query[Transpose] // Dataset


We can also write:

<| "a" -> lista, "b" -> listb, "c" -> listc |> // Dataset // Transpose


... but version 10.4 introduced a regression where the resulting dataset loses its type information (the expression works fine in versions 10.1, 10.2 and 10.3).

• +1. I was waiting for you to chime in :). Yeah, I realized the Dataset functionality goes through changes all the time with no mention of these changes in the documentation. – RunnyKine Apr 4 '16 at 21:53
• makes it hard to write and reuse code when Dataset is such a moving target – Mike Honeychurch Apr 5 '16 at 0:13
• @MikeHoneychurch Yes, I tend to avoid Dataset myself. Its main purpose is to visualize data and I find its visualizations to be problematic maybe 50% of the time. It seems to be overly sensitive to the inferred data types, especially when associations are involved. And a moving target, as you say. Query, on the other hand, I have grown to like. It is more stable than Dataset and I find the "generalized index notation" to be very expressive. – WReach Apr 5 '16 at 13:05
• @WReach thanks for your 2 cents. I'll spend some more time with Query – Mike Honeychurch Apr 5 '16 at 22:48