Append a list as a column in a dataset
One way:
ds // Transpose // Append["intervals" -> intervals] // Transpose
In Mathematica it is usually easier to operate on rows, which is what this solution demonstrates. I would have done the same if I was working with lists too. However, as other answers show there are dataset specific solutions that might work better.
Another way:
ds[MapThread[Append[#1, "intervals" -> #2] &, {#, intervals}] &]
Suppose your column is a list of Association
objects or a Dataset
:
ds = Dataset[{
<|"char" -> 1, "freq" -> 0.1|>,
<|"char" -> 2, "freq" -> 0.2|>,
<|"char" -> 3, "freq" -> 0.3|>,
<|"char" -> 0, "freq" -> 0.4|>
}];
intervals = {{0, 0.4}, {0.4, 0.7}, {0.7, 0.9}, {0.9, 1.}};
assoc=<|"interval"->#|>& /@ intervals;
col = Dataset[assoc];
Then you can simply use Join
to add a column:
Join[ds, assoc, 2]
Join[ds, col, 2]