# Displaying column data as columns?

**URL:** https://discourse.julialang.org/t/displaying-column-data-as-columns/72855
**Category:** New to Julia
**Tags:** question
**Created:** [December 9, 2021, 8:09pm UTC](https://discourse.julialang.org/t/displaying-column-data-as-columns/72855 "2021-12-09T20:09:09Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [December 9, 2021, 8:09pm UTC](https://discourse.julialang.org/t/displaying-column-data-as-columns/72855/1 "2021-12-09T20:09:09Z")

</div>

A is a 1-column data with 3 elements:  
`A = [1, 2, 3, 4, 5];`

Right now, if do the below:  
`@show A;`

The below will be shown on my REPL:  
`A = [1, 2, 3, 4, 5];`

Is there a way I can set up Julia, so that it will display column data as columns, just like what Matlab is doing? For example, in this case, I would see the below:

```julia
A = 
1
2
3
4
5

```

Thanks.

---

<div class="post-metadata">

### Author: ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)
#### Post date: [December 9, 2021, 8:11pm UTC](https://discourse.julialang.org/t/displaying-column-data-as-columns/72855/2 "2021-12-09T20:11:23Z")

</div>

```julia
julia> A = [1, 2, 3, 4, 5];

julia> A
5-element Vector{Int64}:
 1
 2
 3
 4
 5

```

also

```julia
julia> display(A)
5-element Vector{Int64}:
 1
 2
 3
 4
 5

```

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [December 9, 2021, 10:26pm UTC](https://discourse.julialang.org/t/displaying-column-data-as-columns/72855/3 "2021-12-09T22:26:34Z")

</div>

Many thanks!

Maybe that is not a good example. Sometimes the output of my program will display column data as if they are rows, which I find very confusing.

> [@leon](#):
>
> A = [1, 2, 3, 4, 5];

---

<div class="post-metadata">

### Author: ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)
#### Post date: [December 10, 2021, 7:58am UTC](https://discourse.julialang.org/t/displaying-column-data-as-columns/72855/4 "2021-12-10T07:58:31Z")

</div>

One of the other things the output does is (wisely) truncate the middle of a long array when printing. But also sometimes, if I have a DataFrame with 60 columns and do names(df) I _want_ all 60 names so I can scroll through them.

Quick & dirty would be:

`map(println, A);`

The semi-colon is so you also don’t print the _result of map_ which is one `nothing` for evey element

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [December 10, 2021, 1:33pm UTC](https://discourse.julialang.org/t/displaying-column-data-as-columns/72855/5 "2021-12-10T13:33:11Z")

</div>

> [@lawless-m](#):
>
> Quick & dirty would be:
> 
> `map(println, A);`

Instead of using a `map` with `;`, you should be just using:

`foreach(println, A)`

Which is a `map` that always returns `nothing` (does not save the values to arrays).

For displaying in a single line without a limit on the number of elements you can do: `show(IOContext(stdout, :limit => false), A)`.

---

<div class="post-metadata">

### Author: ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)
#### Post date: [December 10, 2021, 1:34pm UTC](https://discourse.julialang.org/t/displaying-column-data-as-columns/72855/6 "2021-12-10T13:34:42Z")

</div>

“Quick & dirty would be”

for some values of “should”. foreach is 3 more letters to type

and the second one even longer

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [December 10, 2021, 1:43pm UTC](https://discourse.julialang.org/t/displaying-column-data-as-columns/72855/7 "2021-12-10T13:43:02Z")

</div>

For some values of “quick”: `map` is allocating a whole new vector even if you are not displaying it, XD.

Also, you can be sure I will forget about the `;` enough times to just be faster to type `foreach` instead of `map` + `;`.

---

<div class="post-metadata">

### Author: ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)
#### Post date: [December 10, 2021, 3:43pm UTC](https://discourse.julialang.org/t/displaying-column-data-as-columns/72855/8 "2021-12-10T15:43:39Z")

</div>

You don’t need to worry about row vs column vectors in Julia as you do in Matlab. A Julia `Vector` is neither a row nor a column because it is truly 1-Dimensional and does not know about any other dimensions to orient itself against.

If you slice a `Matrix` in Julia in either direction, the result is a 1D `Vector` that forgets about its previous orientation.

```julia
julia> A = [1 2 3; 4 5 6; 7 8 9]
3×3 Matrix{Int64}:
 1 2 3
 4 5 6
 7 8 9

julia> A[1,:]
3-element Vector{Int64}:
 1
 2
 3

julia> A[:,1]
3-element Vector{Int64}:
 1
 4
 7

```

I can think of two examples where a row is strictly treated as a row:

1. Plots.jl will sometimes ask for a 1x? `Matrix` as input rather than a `Vector`. This looks like a Matlab row vector but is really a special case of the 2D `Matrix` data type.

```julia
julia> A = [1 2 3 4 5]
1×5 Matrix{Int64}:
1 2 3 4 5

```

1. DataFrames.jl has a `DataFrameRow` type. It is used to preserve extra information about the data frame that would be lost if the data was presented as a `Vector`. For example, it has the special ability to be indexed by column name.

```julia
julia> using DataFrames

julia> df = DataFrame(A=[1,2,3],B=[4,5,6])
3×2 DataFrame
 Row │ A B     
     │ Int64 Int64 
─────┼──────────────
   1 │ 1 4
   2 │ 2 5
   3 │ 3 6

julia> df[:,1]
3-element Vector{Int64}:
 1
 2
 3

julia> df[1,:]
DataFrameRow
 Row │ A B     
     │ Int64 Int64
─────┼──────────────
   1 │ 1 4

julia> df[1,:]["B"]
4
```

---

<div class="post-metadata">

### Author: ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)
#### Post date: [December 20, 2021, 11:15am UTC](https://discourse.julialang.org/t/displaying-column-data-as-columns/72855/9 "2021-12-20T11:15:41Z")

</div>

I came across this today

```julia
julia> using TerminalPager
julia> pager(rand(100))
100-element Vector{Float64}:
 0.3744263500648872
 0.13999473684421915
 0.27656898057508084
 0.8730220303287213
 0.3426440636338286
 0.8960220731666186
 0.396795813237402
 0.8495009604983786
 0.3469971171086582
 0.04243121442940978
 0.10625742146140316
 0.05642715944299159
 0.20889060271420368
:

```

and the colon at the end is waiting for space/enter or q like more(1)
