# Adding a line to the end of an Array

**URL:** https://discourse.julialang.org/t/adding-a-line-to-the-end-of-an-array/42291
**Category:** New to Julia
**Created:** [June 30, 2020, 9:05am UTC](https://discourse.julialang.org/t/adding-a-line-to-the-end-of-an-array/42291 "2020-06-30T09:05:50Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)
#### Post date: [June 30, 2020, 9:05am UTC](https://discourse.julialang.org/t/adding-a-line-to-the-end-of-an-array/42291/1 "2020-06-30T09:05:50Z")

</div>

I have a 18×12 Array{Any,2} called “stock”. I also have a 12×1 vector called “flow”.

My aim is to add the content of flow to the end of stock (essentially adding a new row to stock).

I have tried

```
 stock = [stock;flow']

```

But I get the error “MethodError: no method mathing adjoint(::String)”

How can I get the job done?

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [June 30, 2020, 9:08am UTC](https://discourse.julialang.org/t/adding-a-line-to-the-end-of-an-array/42291/2 "2020-06-30T09:08:49Z")

</div>

```julia
julia> a=[1 2 3;4 5 6]
2×3 Array{Int64,2}:
 1 2 3
 4 5 6

julia> b=[7 8 9]
1×3 Array{Int64,2}:
 7 8 9

julia> vcat(a,b)
3×3 Array{Int64,2}:
 1 2 3
 4 5 6
 7 8 9

```

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [June 30, 2020, 9:09am UTC](https://discourse.julialang.org/t/adding-a-line-to-the-end-of-an-array/42291/3 "2020-06-30T09:09:47Z")

</div>

You may have to transpose your flow:  
`vcat(stock,flow')`

---

<div class="post-metadata">

### Author: ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)
#### Post date: [June 30, 2020, 9:16am UTC](https://discourse.julialang.org/t/adding-a-line-to-the-end-of-an-array/42291/4 "2020-06-30T09:16:28Z")

</div>

I think the basic problem is that flow’ does not work:

![image](https://global.discourse-cdn.com/julialang/original/3X/9/a/9a7aecdf687aa5b9d0d152f4079513eaa4950399.png)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/3/5/356abc9a309438ab0df5b5bc3d7097352da34668.png)

---

<div class="post-metadata">

### Author: ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)
#### Post date: [June 30, 2020, 9:19am UTC](https://discourse.julialang.org/t/adding-a-line-to-the-end-of-an-array/42291/5 "2020-06-30T09:19:09Z")

</div>

> [@Nash](#):
>
> I think the basic problem is that flow’ does not work:

Try `permutedims(flow)`.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [June 30, 2020, 9:32am UTC](https://discourse.julialang.org/t/adding-a-line-to-the-end-of-an-array/42291/6 "2020-06-30T09:32:07Z")

</div>

Is this basically the same problem you posted an hour ago?

> [@Adding a line to the end of an Array](https://discourse.julialang.org/t/adding-a-line-to-the-end-of-an-array/42291):
>
> I have a 18×12 Array{Any,2} called “stock”. I also have a 12×1 vector called “flow”. My aim is to add the content of flow to the end of stock (essentially adding a new row to stock). I have tried stock = [stock;flow'] But I get the error “MethodError: no method mathing adjoint(::String)” How can I get the job done?

---

<div class="post-metadata">

### Author: ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)
#### Post date: [June 30, 2020, 10:02am UTC](https://discourse.julialang.org/t/adding-a-line-to-the-end-of-an-array/42291/7 "2020-06-30T10:02:02Z")

</div>

> [@rfourquet](#):
>
> permutedims(flow)

My other question did not contain the necessary information, so I requested it deleted and then posted this update. Sorry for any inconvenience.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [June 30, 2020, 10:17am UTC](https://discourse.julialang.org/t/adding-a-line-to-the-end-of-an-array/42291/8 "2020-06-30T10:17:14Z")

</div>

You can just update the thread instead. Now there are two threads about adding stuff to a matrix in the most recent thread list.

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [June 30, 2020, 10:42am UTC](https://discourse.julialang.org/t/adding-a-line-to-the-end-of-an-array/42291/9 "2020-06-30T10:42:20Z")

</div>

Just to summarize the answer to your question from the different posts:

You are trying to add a 12 element vector as a row to an 18x12 matrix. You can think of this as vertically concatenating the two. Vectors in Julia are however column vectors by default, and you are looking to append a row vector, so you need to permute the dimensions:

```julia
julia> a = rand(3, 2)
3×2 Array{Float64,2}:
 0.387527 0.230343
 0.682296 0.255378
 0.22481 0.838333

julia> b = rand(2)
2-element Array{Float64,1}:
 0.24946180391946426
 0.24528450122180612

julia> vcat(a, b) # doesn't work as b is 2x1 rather than 1x2
ERROR: ArgumentError: number of columns of each array must match (got (2, 1))
Stacktrace:
 [1] _typed_vcat(::Type{Float64}, ::Tuple{Array{Float64,2},Array{Float64,1}}) at .\abstractarray.jl:1358
 [2] typed_vcat at .\abstractarray.jl:1372 [inlined]
 [3] vcat(::Array{Float64,2}, ::Array{Float64,1}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\SparseArrays\src\sparsevector.jl:1078
 [4] top-level scope at REPL[114]:1

julia> vcat(a, b')
4×2 Array{Float64,2}:
 0.387527 0.230343
 0.682296 0.255378
 0.22481 0.838333
 0.249462 0.245285

```

`vcat` is the same as doing `[a; b']`, i.e. the array syntax with a semicolon is syntactic sugar for `vcat`:

```julia
julia> [a; b']
4×2 Array{Float64,2}:
 0.387527 0.230343
 0.682296 0.255378
 0.22481 0.838333
 0.249462 0.245285

```

Your other problemn is that your `b` includes non-numerical values, for which `'`, which produces an adjoint, doesn’t work - see the discussion [here](https://discourse.julialang.org/t/transpose-of-an-array-of-strings/40431/3). You therefore need `permutedims` to get your vector into a row vector.
