Multiple Range Index Array

Julia arrays support indexing with multiple ranges, such as

dat = Array(1:10) # trying to get dat[[1:3, 6:8]] to result in dat[[1,2,3,6,7,8]] 

Looking for something that looks like the equivalent of R dat[c(1:3, 6:8)] ?

+5
source share
1 answer

The direct equivalent of version R is

 v = 1:10 v[ [1:3; 6:8] ] 

since ; - concatenation operator:

 julia> [1:3; 6:8] 6-element Array{Int64,1}: 1 2 3 6 7 8 

You can also see chain in Iterators.jl package: https://github.com/JuliaLang/Iterators.jl

+8
source

Source: https://habr.com/ru/post/1258639/


All Articles