[R] help with one matrix

Jim Lemon bitwrit at ozemail.com.au
Sun Sep 11 13:08:43 CEST 2005


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




More information about the R-help mailing list