[R] changing the value of a variable from inside a function

tom wright tom at maladmin.com
Tue Nov 15 13:35:24 CET 2005


Michael,
I feel sure people are going to come up with other better suggestions
here but does <- work for you?
test <- matrix(NA,nrow=4,ncol=3)
test[1,] <- c(1,2,3)
blah <- function(i){
   test[i,] <<- c(0,1,2) + i
   return(test)
}


On Tue, 2005-15-11 at 12:22 -0500, Michael Wolosin wrote:
> test <- matrix(NA,nrow=4,ncol=3)
> test[1,] <- c(1,2,3)
> blah <- function(i){
>    test[i,] <- c(0,1,2) + i
>    return(test)
> }
> test
> blah(2)
> test




More information about the R-help mailing list