# How can we combine two column of same dataset?

dataset = Dataset[{
<|"a" -> 1, "b" -> "x", "c" -> {1}|>,
<|"a" -> 2, "b" -> "y", "c" -> {2, 3}|>,
<|"a" -> 3, "b" -> "z", "c" -> {3}|>,
<|"a" -> 4, "b" -> "x", "c" -> {4, 5}|>,
<|"a" -> 5, "b" -> "y", "c" -> {5, 6, 7}|>,
<|"a" -> 6, "b" -> "z", "c" -> {}|>}]


I want to join column 'b' and 'c'. So that we have dataset of column 'a' and 'b'.Column b contianin the values of both 'b' and 'c'

• Is this what you need <|"a" -> #a, "b" -> {#b, #c}|> & /@ dataset – Kuba Aug 26 '16 at 10:55

Here is one way:

dataset[All, <| "a" -> "a", "b" -> (Prepend[#c, #b] &) |>] I'm praying there is a better way to do this, but this is my take:

First, you take the first column and store it:

a1 = dataset[All, {"a"}] // Normal


then, you extract the remaining two columns of interest:

cols = dataset[All, {"b", "c"}];


Finally, you merge the rows of the two columns and then create a new dataset with the original column "a" and the newly calculated second column (new "b"):

f[assoc_] := <|"b" -> Flatten[{assoc["b"], assoc["c"]}]|>
a2 = cols[All, f[#] &] // Normal

dataset2 = Dataset@Apply[Append[#1, #2] &, Transpose[{a1, a2}], 1]

• Nothing wrong with the way you are doing it, but since you prayed about it, you can modify Kuba's method to get the same result: <|"a" -> #a, "b" -> Flatten@{#b, #c}|> & /@ dataset seems the same as your dataset2 – Jason B. Aug 26 '16 at 16:11
• As a matter of fact, I did, and yes, you're right, it does work the same. Thanks! – user42582 Aug 26 '16 at 16:15