# Issues in assigning combinations to indices and appending values to arrays

**URL:** <https://discourse.julialang.org/t/issues-in-assigning-combinations-to-indices-and-appending-values-to-arrays/52771>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 3, 2021, 11:26am UTC](https://discourse.julialang.org/t/issues-in-assigning-combinations-to-indices-and-appending-values-to-arrays/52771 "2021-01-03T11:26:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdsa3d](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mdsa3d/32/20389_2.png) [@mdsa3d](https://discourse.julialang.org/u/mdsa3d)\
**Post date:** [January 3, 2021, 11:26am UTC](https://discourse.julialang.org/t/issues-in-assigning-combinations-to-indices-and-appending-values-to-arrays/52771/1 "2021-01-03T11:26:42Z")

</div>

I would like to seek advice on this code snippet,

```julia
results, xi, xj = ([] for count in 1:6)
for comb in c
  i, j = comb #assign the rows of comb[i] to i and comb[j] to j
  result = algae(xi = df1[:, i], xj = df2[:, j], y = tool)
  append!(xi, i)
  append!(xj, j)
  append!(results, result)
end

```

Here `c` is a combinations range, `algae` is an external function which is measuring the values and `df1, df2, y` are dataframes which are used as inputs.

1. The first issue is that the `xi, xj` is not taking in values from `df1 and df2` .
2. Secondly, I want to append or store the values for each iteration in an empty array (previously  
initialized) but it does not perform this operation.

My objective is to be able to print the an array showing xi, xj and result.

Please suggest a solution for this problem.  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [January 3, 2021, 1:23pm UTC](https://discourse.julialang.org/t/issues-in-assigning-combinations-to-indices-and-appending-values-to-arrays/52771/2 "2021-01-03T13:23:45Z")

</div>

Please ensure that you link questions if cross-posting on multiple sites - this was asked originally on StackOverflow [here](https://stackoverflow.com/questions/65527235/how-to-append-the-values-of-input-and-calculated-result-from-a-function-in-julia?noredirect=1#comment115885645_65527235).

As I said in the SO comment, it’s hard to help without a minimum working example, please read [this thread](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757/81) for further help.

Here’s a minimum example that addresses your second point (slightly elongated from what I posted in my SO comment as there’s no character limit here!):

```julia
julia> xi, xj = ([] for _ ∈ 1:2)
Base.Generator{UnitRange{Int64}, var"#1#2"}(var"#1#2"(), 1:2)

julia> for c ∈ zip(1:5, 6:10)
           i, j = c
           append!(xi, i)
           append!(xj, j)
       end

julia> xi
5-element Vector{Any}:
 1
 2
 3
 4
 5

julia> xj
5-element Vector{Any}:
  6
  7
  8
  9
 10

```

This is why a minimum working example is useful - your code does not show what `c` actually is (what is a “combinations range”?), nor does it show what the output of your loop is and how it’s different from what you expected (i.e. in what sense did the code “not perform this operation”).

I also don’t see anything wrong with your call to `algae` on the face of it, and it’s not clear to me what “`xi, xj` is not taking in values from `df1` and `df2`” actually means - again it would be helpful if your code actually demonstrated your issue in a reproducible manner.
