Or write `a[(1:3)[1:2]] = 1` instead. I'm also very unclear on what's going on in R since R does not return a view object. Moreover, we have this:
> a <- c(0,0,0,0,0) > a[1:3][1:2] <- 1 > a [1] 1 1 0 0 0 Yet we also have this: > a <- c(0,0,0,0,0) > b <- a[1:3] > b[1:2] <- 1 > a [1] 0 0 0 0 0 Huh? So apparently the `a[1:3]` part of `a[1:3][1:2]` cannot be considered a proper subexpression. In other words, `a[1:3]` here does not do what `a[1:3]` by itself does – it is inextricably connected to the following `[1:2]` in some fashion. This interpretation seems to be supported by the fact that attempting to parenthesize this part is an error: > a <- c(0,0,0,0,0) > (a[1:3])[1:2] <- 1 Error in (a[1:3])[1:2] <- 1 : could not find function "(<-" Can any R expert explain this behavior? On Sun, Aug 21, 2016 at 4:43 AM, 'Greg Plowman' via julia-users < [email protected]> wrote: > But also note that a[1:3] = 1.0 will modify a (rather than a copy) > > On Sunday, August 21, 2016 at 6:34:28 PM UTC+10, Kristoffer Carlsson wrote: >> >> Range indexing produces copies yes. Either just write the loops or use >> "view" or "sub" to refer to the original memory. > >
