# Better way to have "filled" ranges?

**URL:** https://discourse.julialang.org/t/better-way-to-have-filled-ranges/122383
**Category:** General Usage
**Tags:** range
**Created:** [November 7, 2024, 3:28pm UTC](https://discourse.julialang.org/t/better-way-to-have-filled-ranges/122383 "2024-11-07T15:28:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [November 7, 2024, 3:28pm UTC](https://discourse.julialang.org/t/better-way-to-have-filled-ranges/122383/1 "2024-11-07T15:28:20Z")

</div>

Is there a better (more elegant) way of the one below in order to obtain a vector representing ranges filled with the first element of the range ?

```julia
years = collect(2000:2019)
step = 5
desired_res = [2000,2000,2000,2000,2000,2005,2005,2005,2005,2005,2010,2010,2010,2010,2010,2015,2015,2015,2015,2015]

```

What I have found:

```julia
period_ranges = collect(Iterators.partition(years[1]:years[end], step))
periods = [period_ranges[findfirst(p->in(y,p),period_ranges)][1] for y in years]

```

---

<div class="post-metadata">

### Author: ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)
#### Post date: [November 7, 2024, 3:34pm UTC](https://discourse.julialang.org/t/better-way-to-have-filled-ranges/122383/2 "2024-11-07T15:34:16Z")

</div>

Does `repeat(years[begin:step:end], inner = step)` do it?

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [November 7, 2024, 4:11pm UTC](https://discourse.julialang.org/t/better-way-to-have-filled-ranges/122383/3 "2024-11-07T16:11:26Z")

</div>

I knew there was ! 😉
