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

2008-06-20 Thread Wacek Kusnierczyk
Wacek Kusnierczyk wrote: > Ken Liu wrote: > >> 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,

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

2008-06-20 Thread Wacek Kusnierczyk
Ken Liu wrote: > 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 matr

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

2008-06-20 Thread Ken Liu
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