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

**URL:** https://discourse.julialang.org/t/in-julia-how-to-realize-a-b-1-2-as-in-r-without-modifying-b/1447
**Category:** New to Julia
**Created:** [January 12, 2017, 7:46pm UTC](https://discourse.julialang.org/t/in-julia-how-to-realize-a-b-1-2-as-in-r-without-modifying-b/1447 "2017-01-12T19:46:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![WenlongGong](https://avatars.discourse-cdn.com/v4/letter/w/3d9bf3/32.png) [@WenlongGong](https://discourse.julialang.org/u/WenlongGong)
#### Post date: [January 12, 2017, 7:46pm UTC](https://discourse.julialang.org/t/in-julia-how-to-realize-a-b-1-2-as-in-r-without-modifying-b/1447/1 "2017-01-12T19:46:45Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [January 12, 2017, 7:48pm UTC](https://discourse.julialang.org/t/in-julia-how-to-realize-a-b-1-2-as-in-r-without-modifying-b/1447/2 "2017-01-12T19:48:38Z")

</div>

See [Julia equivalent to 'not in' in R](https://discourse.julialang.org/t/julia-equivalent-to-not-in-in-r/835)

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [January 12, 2017, 7:53pm UTC](https://discourse.julialang.org/t/in-julia-how-to-realize-a-b-1-2-as-in-r-without-modifying-b/1447/3 "2017-01-12T19:53:14Z")

</div>

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

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

```

Of course for these particular elements,

```julia
b[3:end]

```

will also work.

---

<div class="post-metadata">

### Author: ![WenlongGong](https://avatars.discourse-cdn.com/v4/letter/w/3d9bf3/32.png) [@WenlongGong](https://discourse.julialang.org/u/WenlongGong)
#### Post date: [January 12, 2017, 8:03pm UTC](https://discourse.julialang.org/t/in-julia-how-to-realize-a-b-1-2-as-in-r-without-modifying-b/1447/4 "2017-01-12T20:03:47Z")

</div>

That helps! Thanks both of you for the reply!
