The logic is:
julia> function identify_pairs(v::AbstractVector)
local start, stop
initialized = false
res = eltype(v)[]
for x in v
if initialized
if x == stop + 1
stop = x
else
if stop > start
push!(res, start, stop)
initialized = false
end
start = stop = x
initialized = true
end
else
start = stop = x
initialized = true
end
end
if stop > start
push!(res, start, stop)
end
return res
end
identify_pairs (generic function with 1 method)
julia> transform(df, :list => ByRow(identify_pairs) => :new)
3×2 DataFrame
Row │ list new
│ Array… Array…
─────┼────────────────────────────────────────────────
1 │ [1, 2, 3, 6, 12, 13, 14] [1, 3, 12, 14]
2 │ [20, 21, 23, 24, 50] [20, 21, 23, 24]
3 │ [1, 3, 5, 7, 10, 11, 12, 13] [10, 13]