Consider the following R-code:
i <- 10
j <- 0
m <- matrix(c(1,2,3,4,5,6), nrow = 3, ncol = 2, byrow = TRUE)
apply(m, 1, function(x) {
if(i > 0)
j<-1
else
j<-2
return <- i
})
Inside the function we can read the content of the variable i, but we cannot manipulate the content of the variable j? But when we can read variables inside the function I would expect that we can assign new values to them too? So can someone explain what is happening here?