# Create named array in Julia

**URL:** <https://discourse.julialang.org/t/create-named-array-in-julia/77476>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 6, 2022, 2:21pm UTC](https://discourse.julialang.org/t/create-named-array-in-julia/77476 "2022-03-06T14:21:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [March 6, 2022, 2:21pm UTC](https://discourse.julialang.org/t/create-named-array-in-julia/77476/1 "2022-03-06T14:21:04Z")

</div>

Hello,  
I am generating an array with some numeric parameters that then I pass to a function as:

```julia
parms = [1,2,3,4,5]
function x!(pt)
    μ, κ, δ, ω, η = p
    return( ((μ+κ)*(δ+ω))^(1/η) )
end
x(parms)

```

It would be useful to address the single parameters by name, so that I can have flexibility in the definition of the function. That is: I don’t have to put the arguments in the same order as the function’s structure. This is equivalent to R’s

```julia
parms <- c(kappa=2, mu=1, delta=3, eta=5, omega=4)
x <- function(p) {
  m = p["mu"]
  k = p["kappa"]
  d = p["delta"]
  o = p["omega"]
  e = p["eta"]
  return( ((m+k)*(d+o))^(1/e) )
}
x(parms)

```

I have seen some people use `TOML` but I think it is an overkill and generates files .tomls that break the Julia environment.  
Thanks

---

<div class="post-metadata">

**Author:** ![Jordan\_Cluts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jordan_cluts/32/13753_2.png) [@Jordan\_Cluts](https://discourse.julialang.org/u/Jordan_Cluts)\
**Post date:** [March 6, 2022, 2:24pm UTC](https://discourse.julialang.org/t/create-named-array-in-julia/77476/2 "2022-03-06T14:24:30Z")

</div>

Checking out [Named Tuples](https://docs.julialang.org/en/v1/manual/types/#Named-Tuple-Types).

---

<div class="post-metadata">

**Author:** ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Post date:** [March 6, 2022, 2:42pm UTC](https://discourse.julialang.org/t/create-named-array-in-julia/77476/3 "2022-03-06T14:42:50Z")

</div>

Yep, you’re right. From your solution I have found [a post](https://www.geeksforgeeks.org/namedtuple-in-julia/):

```julia
# Creating a NamedTuple with similar values
tupl2 = (a = 1, b = 2, c = 4, d = 5)
# Accessing using Index value
println(tupl2[2])
# Accessing using assigned value name
println(tupl3[:b])

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 6, 2022, 4:15pm UTC](https://discourse.julialang.org/t/create-named-array-in-julia/77476/4 "2022-03-06T16:15:29Z")

</div>

Even more conveniently, you can access like this: `tupl3.b`.
