# How can I swap columns of InMemoryDatasets?

**URL:** <https://discourse.julialang.org/t/how-can-i-swap-columns-of-inmemorydatasets/84808>\
**Category:** General Usage\
**Tags:** question, inmemorydatasets\
**Created:** [July 26, 2022, 10:43am UTC](https://discourse.julialang.org/t/how-can-i-swap-columns-of-inmemorydatasets/84808 "2022-07-26T10:43:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [July 26, 2022, 10:43am UTC](https://discourse.julialang.org/t/how-can-i-swap-columns-of-inmemorydatasets/84808/1 "2022-07-26T10:43:05Z")

</div>

I have the following example:

```julia
using InMemoryDatasets

g1 = repeat(1:6, inner = 4);
g2 = repeat(1:4, 6);
y = ["d8888b. ", " .d8b. ", "d888888b ", " .d8b. ", "88 `8D ", "d8' `8b ",
            "` ~~88~~' ", " d8' `8b ", "88 88 ", "88ooo88 ", " 88 ", " 88ooo88 ",
            "88 88 ", "88 ~~~88 ", " 88 ", " 88~~~ 88 ", "88 .8D ", "88 88 ",
            " 88 ", " 88 88 ", "Y8888D' ", "YP YP ", " YP ", " YP YP "];
ds = Dataset(g1 = g1, g2 = g2, y = y)

```

How can I swap the first and second column of ds?

---

<div class="post-metadata">

**Author:** ![hellemo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hellemo/32/324_2.png) [@hellemo](https://discourse.julialang.org/u/hellemo)\
**Post date:** [July 26, 2022, 10:49am UTC](https://discourse.julialang.org/t/how-can-i-swap-columns-of-inmemorydatasets/84808/2 "2022-07-26T10:49:51Z")

</div>

Like

```julia
select!(ds, [:g2, :g1, :y])

```

?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [July 26, 2022, 4:41pm UTC](https://discourse.julialang.org/t/how-can-i-swap-columns-of-inmemorydatasets/84808/3 "2022-07-26T16:41:43Z")

</div>

Not sure if this is documented anywhere, but it works perfectly! 🙂

---

<div class="post-metadata">

**Author:** ![DataFrames](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@DataFrames](https://discourse.julialang.org/u/DataFrames)\
**Post date:** [August 5, 2022, 4:38am UTC](https://discourse.julialang.org/t/how-can-i-swap-columns-of-inmemorydatasets/84808/4 "2022-08-05T04:38:33Z")

</div>

use `?select` for doc. What I found is that `select` in `InMemoryDatasets` in contrast to `DataFrames` only does “selecting” and using `Not` drops the column in the output.
