[R] unable to update the matrix values within a function

From: Ken Liu <tyliu0522_at_yahoo.com>
Date: Fri, 20 Jun 2008 16:41:43 -0700 (PDT)


Hi,

I don't understand why this doesn't work:

matTest <- matrix(nrow=3, ncol=3)
testMove <- function(I, J){

    for(i in 1:I){

        for(j in 1:J){
            matTest[i, j] <- i+j
        }

    }
}
testMove(2, 3)
matTest

Why the elements of the matrix matTest are still NA? How could I fix it?

Thanks,
Ken



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 21 Jun 2008 - 05:11:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 21 Jun 2008 - 07:30:47 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive