In julia, how to realize a=b[-1:2] as in R without modifying b


#1

Basically, I want to make a copy of some array b after removing some elements. but not change the original b.
I tried splice!(b,1:2) and deleteat!(b,1:2) both would change b.
Thanks for any comments!


#2

See Julia equivalent to 'not in' in R


#3

Julia has no built-in syntax that is equivalent to R’s vector[-indexes]. Try something like

a = b[setdiff(1:end,indexes_to_remove)]

Of course for these particular elements,

b[3:end]

will also work.


#4

That helps! Thanks both of you for the reply!