# Using push! to add a new row of data

**URL:** <https://discourse.julialang.org/t/using-push-to-add-a-new-row-of-data/86519>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 29, 2022, 9:43pm UTC](https://discourse.julialang.org/t/using-push-to-add-a-new-row-of-data/86519 "2022-08-29T21:43:42Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [August 29, 2022, 10:20pm UTC](https://discourse.julialang.org/t/using-push-to-add-a-new-row-of-data/86519/2 "2022-08-29T22:20:42Z")

</div>

You can only push to vectors, but not to multi-dimensional arrays. (See for example here [Resize!(matrix) - #2 by StefanKarpinski](https://discourse.julialang.org/t/resize-matrix/2379/2) why it is this way.)

- If you really need to add rows dynamically, you could consider using a `Vector` of `Vectors`

```julia
LL = Vector{Float64}[]
push!(LL, [1.0, 2.0])

```

or maybe you could use [Introduction · DataFrames.jl](https://dataframes.juliadata.org/stable/) or [GitHub - JuliaArrays/ElasticArrays.jl: Resizeable multi-dimensional arrays for Julia](https://github.com/JuliaArrays/ElasticArrays.jl)

- If you only need to add a few rows/columns, you could use `vcat` or `hcat`. For example

```julia
LL = [X[:] Y[:]] # or hcat(X[:],Y[:]) or hcat(vec(X),vec(Y))

```

- If you know in advance how many rows you need, that is of course ideal and it can sometimes give great performance benefits.

```julia
LL = fill(NaN, n*m, 2) # or LL = Array{Float64}(undef, n*m, 2)
k = 1
for j ∈ 1:n #180
    for i ∈ 1:m #360
        LL[k, :] .= (X[i,j], Y[i,j])
        k += 1
    end
end

```

---

_[View the full topic](https://discourse.julialang.org/t/using-push-to-add-a-new-row-of-data/86519)._
