# Increase a range object by some amount

**URL:** https://discourse.julialang.org/t/increase-a-range-object-by-some-amount/27286
**Category:** General Usage
**Tags:** question
**Created:** [August 7, 2019, 8:55pm UTC](https://discourse.julialang.org/t/increase-a-range-object-by-some-amount/27286 "2019-08-07T20:55:54Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![mgalenb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mgalenb/32/5645_2.png) [@mgalenb](https://discourse.julialang.org/u/mgalenb)
#### Post date: [August 7, 2019, 8:55pm UTC](https://discourse.julialang.org/t/increase-a-range-object-by-some-amount/27286/1 "2019-08-07T20:55:54Z")

</div>

Hello,

I am trying to increase a range object that has already been created. Basically, I have a range `1,2,3,..,8,9,10` and then i want to add `11,12,13` to the same range object so that i will get a final range of `1,2,3,...11,12,13`. Is there a way to do this?

```julia
julia> r1=1:10
1:10

julia> r2=11:13
11:13

julia> r1+r2
ERROR: DimensionMismatch("argument dimensions must match")
Stacktrace:
  [1] +(::UnitRange{Int64}, ::UnitRange{Int64}) at .\range.jl:1005
 [2] top-level scope at none:0

```

What am i doing wrong?  
Thanks

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [August 7, 2019, 9:12pm UTC](https://discourse.julialang.org/t/increase-a-range-object-by-some-amount/27286/2 "2019-08-07T21:12:38Z")

</div>

You could just write a function to do:

```julia
julia> @assert last(r1) + 1 == first(r2)

julia> UnitRange(first(r1), last(r2))
1:13

```

You can also `vcat` ranges, but note that this collects them into actual arrays, which is wasteful:

```julia
julia> vcat(r1, r2)
13-element Array{Int64,1}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13

```

---

<div class="post-metadata">

### Author: ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)
#### Post date: [August 7, 2019, 10:11pm UTC](https://discourse.julialang.org/t/increase-a-range-object-by-some-amount/27286/3 "2019-08-07T22:11:32Z")

</div>

> [@mgalenb](#):
>
> r1=1:10 1:10 julia\> r2=11:13

What if r1=1:5 and r2=11:13 ?

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [August 7, 2019, 10:14pm UTC](https://discourse.julialang.org/t/increase-a-range-object-by-some-amount/27286/4 "2019-08-07T22:14:58Z")

</div>

What’s actually being requested here seems to be concatenation of two ranges.

---

<div class="post-metadata">

### Author: ![mgalenb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mgalenb/32/5645_2.png) [@mgalenb](https://discourse.julialang.org/u/mgalenb)
#### Post date: [August 7, 2019, 10:15pm UTC](https://discourse.julialang.org/t/increase-a-range-object-by-some-amount/27286/5 "2019-08-07T22:15:25Z")

</div>

yes concatenation of two ranges

---

<div class="post-metadata">

### Author: ![mgalenb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mgalenb/32/5645_2.png) [@mgalenb](https://discourse.julialang.org/u/mgalenb)
#### Post date: [August 7, 2019, 10:16pm UTC](https://discourse.julialang.org/t/increase-a-range-object-by-some-amount/27286/6 "2019-08-07T22:16:04Z")

</div>

can julia do uneven ranges?

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [August 7, 2019, 10:20pm UTC](https://discourse.julialang.org/t/increase-a-range-object-by-some-amount/27286/7 "2019-08-07T22:20:18Z")

</div>

That won’t in general be a range. If you want it to produce another range then you’ll have to write a function that checks that the strides are the same and that the last endpoint of the first range and the first endpoint of the second range are the same. If you don’t care about producing a range then you can just do `[r1; r2]` which does array concatenation.

---

<div class="post-metadata">

### Author: ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)
#### Post date: [August 7, 2019, 11:15pm UTC](https://discourse.julialang.org/t/increase-a-range-object-by-some-amount/27286/8 "2019-08-07T23:15:06Z")

</div>

> [@StefanKarpinski](#):
>
> and that the last endpoint of the first range and the first endpoint of the second range are the same

Actually, they should probably differ by 1? That seems more in line with arrays concatenation

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [August 7, 2019, 11:24pm UTC](https://discourse.julialang.org/t/increase-a-range-object-by-some-amount/27286/9 "2019-08-07T23:24:29Z")

</div>

Right, that’s what I meant.
