# Adding rows

**URL:** <https://discourse.julialang.org/t/adding-rows/49364>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [October 31, 2020, 1:30pm UTC](https://discourse.julialang.org/t/adding-rows/49364 "2020-10-31T13:30:37Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [October 31, 2020, 5:18pm UTC](https://discourse.julialang.org/t/adding-rows/49364/4 "2020-10-31T17:18:40Z")

</div>

You should always quote your code here with backticks ```, like this:

```julia
m = 1
n = R[1:30]
for t = [1:33][1]
local n
m = m + t
n = t
R2 = sum(R[m])
end
printmat(R2)

```

It makes it much easier to read 😀 Have a look at [this thread](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757/18) when you get a chance.

I’m not sure I’m following but if you have some returns data in a `Matrix` R and then the names of the assets in a vector `assets`, you can do this:

```julia
# Create fake data
R = rand(Float64, (50,30))
assets = ["company$i" for i in 1:30]

rets = [(company=i[2], ret=sum(i[1][1:33])) for i in zip(eachcol(R), assets)]

julia> sorted_assets = [sort(rets, by=last, rev=true)[i][1] for i in 1:30]
30-element Array{String,1}:
 "company18"
 "company11"
 "company6"
 "company29"
 "company7"
 "company5"
 "company1"
 "company30"
 ⋮
 "company15"
 "company3"
 "company26"
 "company21"
 "company20"
 "company2"
 "company22"
 "company14"

```

That being said, I would probably use DataFrames.jl to do this kind of work. The documentation for that package is good and it will probably allow you to get up and running with these kinds of operations faster than if you just use base Julia.

---

_[View the full topic](https://discourse.julialang.org/t/adding-rows/49364)._
