# Create a vector accepting different datatypes at specific index positions

**URL:** <https://discourse.julialang.org/t/create-a-vector-accepting-different-datatypes-at-specific-index-positions/96222>\
**Category:** General Usage\
**Created:** [March 17, 2023, 4:34am UTC](https://discourse.julialang.org/t/create-a-vector-accepting-different-datatypes-at-specific-index-positions/96222 "2023-03-17T04:34:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Name1](https://avatars.discourse-cdn.com/v4/letter/n/ed655f/32.png) [@Name1](https://discourse.julialang.org/u/Name1)\
**Post date:** [March 17, 2023, 4:34am UTC](https://discourse.julialang.org/t/create-a-vector-accepting-different-datatypes-at-specific-index-positions/96222/1 "2023-03-17T04:34:34Z")

</div>

Hi all,

I’m wondering how to initialize a vector that requires different datatypes at specific positions. I want the first element in the array to be of type Int64, and the second element in the array to be of type Float64. The below example code is making both array elements Float64, which I don’t want:

```julia
arr = Vector{Vector{Union{Int64, Float64}}}()

r_arr = [2.0, 4.0, 6.0] 

for ii in 1:4
  for jj in r_arr
    push!(arr, [ii, jj])
  end 
end 

```

Undesirable output below:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/9/49789b838a07657303eebf3bcd2dbdebbb097553.png)

How can I modify my code to force the first element of the vector to be an Int64 and the second element of the vector to be a Float64? Can this be done with vector’s, or will I need to use another data type (e.g. Array)?

Thanks.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [March 17, 2023, 4:35am UTC](https://discourse.julialang.org/t/create-a-vector-accepting-different-datatypes-at-specific-index-positions/96222/2 "2023-03-17T04:35:22Z")

</div>

Are you sure you don’t want a `Vector{Tuple{Int64, Float64}}`

---

<div class="post-metadata">

**Author:** ![Name1](https://avatars.discourse-cdn.com/v4/letter/n/ed655f/32.png) [@Name1](https://discourse.julialang.org/u/Name1)\
**Post date:** [March 17, 2023, 4:39am UTC](https://discourse.julialang.org/t/create-a-vector-accepting-different-datatypes-at-specific-index-positions/96222/3 "2023-03-17T04:39:38Z")

</div>

That one works, cheers.

Is there a way to use a Vector or Array instead of Tuple in this case? I like the mutability of Vectors and Arrays compared to Tuples immutability, but I shouldn’t need to change the Int64 and Float64 values so it ultimately shouldn’t matter much.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [March 17, 2023, 4:53am UTC](https://discourse.julialang.org/t/create-a-vector-accepting-different-datatypes-at-specific-index-positions/96222/4 "2023-03-17T04:53:34Z")

</div>

You could always make a mutable struct that stores an Int and Float64. In general, figuring out a data-structure that naturally represents your data is a good idea.
