Dear Dale, Here is one way, probably not the best: n<-9 temp<-matrix(1,ncol=n,nrow=n) temp[lower.tri(temp)] <- 0 temp
HTH, Jorge On Wed, Feb 11, 2009 at 4:22 PM, Dale Steele <dale.w.ste...@gmail.com>wrote: > The code below create an nxn upper triangular matrix of one's. I'm > stuck on finding a more efficient vectorized way - Thanks. --Dale > > n <- 9 > data <- matrix(data=NA, nrow=n, ncol=n) > data > for (i in 1:n) { > data[,i] <- c(rep(1,i), rep(0,n-i)) > } > data > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.