[R] help with one matrix

Jim Lemon
Sun, 11 Sep 2005 11:08:43 -0000

Is this what you want?

make.odd.matrix<-function(matsize) {
  newmat<-matrix(0,nrow=matsize,ncol=matsize)
  for(i in 1:matsize) {
   for(j in 1:matsize)
    newmat[i,j]<-ifelse(i==j,NA,abs(i-j)+1)
  }
  return(newmat)
}

Jim