Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Index array with multiple ranges

Tags:

arrays

julia

Do julia arrays support indexing with multiple ranges like the following

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 would be like the R equivalent dat[c(1:3, 6:8)]?

like image 203
Rorschach Avatar asked Oct 22 '16 19:10

Rorschach


1 Answers

The direct equivalent of the R version is

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

since ; is the concatenation operator:

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

You may also want to look at chain in the Iterators.jl package: https://github.com/JuliaLang/Iterators.jl

like image 135
David P. Sanders Avatar answered Oct 31 '22 00:10

David P. Sanders