# How to create an OffsetArray from an existing array?

**URL:** <https://discourse.julialang.org/t/how-to-create-an-offsetarray-from-an-existing-array/18461>\
**Category:** General Usage\
**Tags:** array\
**Created:** [December 8, 2018, 2:24pm UTC](https://discourse.julialang.org/t/how-to-create-an-offsetarray-from-an-existing-array/18461 "2018-12-08T14:24:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SZJX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/szjx/32/4036_2.png) [@SZJX](https://discourse.julialang.org/u/SZJX)\
**Post date:** [December 8, 2018, 2:24pm UTC](https://discourse.julialang.org/t/how-to-create-an-offsetarray-from-an-existing-array/18461/1 "2018-12-08T14:24:32Z")

</div>

Sorry if the answer is obvious. I just couldn’t find a solution in the source code or via Googling.

Basically my use case is like this:

```julia
v = Vector{Char}("asdf")

# Doesn't work
offset_v = OffsetVector{Char}("asdf", 0:3)

# Doesn't work
offset_v = OffsetVector{Char}(v, 0:3)

# Doesn't work
offset_v = OffsetVector{Char}(undef, 0:3)
copyto!(offset_v, 0:3, v, 1:4)

# Copies the content but they are now off by one.
circcopy!(offset_v, v)
OffsetArray(::Array{Char,1}, 0:3) with eltype Char with indices 0:3:
 'f'
 'a'
 's'
 'd'

```

Is there an obvious way to do so without having to manually iterate the characters one by one and assign them?

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [December 8, 2018, 8:08pm UTC](https://discourse.julialang.org/t/how-to-create-an-offsetarray-from-an-existing-array/18461/2 "2018-12-08T20:08:20Z")

</div>

The general syntax is `OffsetArray(v, axes...)`:

```julia
julia> OffsetArray(v, 0:3)
OffsetArray(::Array{Char,1}, 0:3) with eltype Char with indices 0:3:
 'a'
 's'
 'd'
 'f'

```

Given that it works for `Vector`, the `OffsetVector{Char}("asdf", 0:3)` syntax seems to make sense, and could be added in a PR to OffsetArrays.
