Iterating through all possibilities

Welcome to the Julia community! First, it’s best to format your code output with backticks ``` like this:

julia> dfV = DataFrame(
           pt1 = rand(1.0:0.01:99.00, 10),
           pt2 = rand(-99.0:0.01:-1.0, 10)
       )
10×2 DataFrame
│ Row │ pt1     │ pt2     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 61.91   │ -67.4   │
│ 2   │ 58.66   │ -2.84   │
│ 3   │ 67.24   │ -74.39  │
│ 4   │ 88.18   │ -5.67   │
│ 5   │ 56.37   │ -61.79  │
│ 6   │ 82.63   │ -87.87  │
│ 7   │ 12.39   │ -83.12  │
│ 8   │ 20.24   │ -97.55  │
│ 9   │ 62.59   │ -42.87  │
│ 10  │ 95.64   │ -12.08  │

You should be able to copy/paste directly from your REPL this way and it’s much easier to see what’s going on. You should also check out this thread.

I’m not 100% certain as to what it is you’re trying to do but for iterating over the rows of a DataFrame you can just do:

for row in eachrow(dfV)
    # do something here...
end

If you need to do some sort of nested iteration, you can do:

for vrow in eachrow(dfV), srow in eachrow(dfS)
    # do something here...
end

It looks like you’re just trying to compute the Euclidean distance between points and I suspect there is a better way of approaching the problem. Distances.jl exports a colwise function as well as a pairwise function so I would probably check those out to see if they do what you need them to.

3 Likes