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