I've seen a couple of people using [<-
as a function with Polish notation, for example
x <- matrix(1:4, nrow = 2)
`[<-`(x, 1, 2, 7)
which returns
[,1] [,2]
[1,] 1 7
[2,] 2 4
I've tried playing around with [<-
a little, and it looks like using it this way prints the result of something like x[1,2] <- 7
without actually performing the assignment. But I can't figure out for sure what this function actually does, because the documentation given for ?"["
only mentions it in passing, and I can't search google or SO for "[<-".
And yes, I know that actually using it is probably a horrible idea, I'm just curious for the sake of a better understanding of R.
x[1,2] <- 7
to bex <- '[<-'(x, 1, 2, 7)
. – Sikorski[
function and the<-
function, then the[<-
function makes a lot of sense. Try[(x,1,2)
. Try<-(a,1)
– Croon[<-
doesn't actually effect a sub-assignment in the symbol/named objectx
. That did not appear to be the question posed in the nominated duplicate. – Drier"[<-"
is a function that returns the accordingly modified object. That is what"[<-"(x, i, value)
seems to do. To see the difference between the explicit"[<-"
call and howx[i] <- value
is parsed, perhaps, see'*tmp*' = "tmp"; x = 1:3; x[2] <- 0; x; get("*tmp*")
VS'*tmp*' = "tmp"; x = 1:3; "[<-"(x, 2, 0); x; get("*tmp*")
as noted here. – Quillan