Dear William, Here is one way using Henrique's solution:
Make <- function(x, nR, nC){ m <- matrix(0, nrow = nR, ncol = nC) diag(m) <- x[1] diag(m[-1,]) <- x[2] m } Make(x = c(1,2), nR = 5, nC = 4) HTH, Jorge On Sat, Jul 4, 2009 at 11:59 AM, William Simpson < william.a.simp...@gmail.com> wrote: > Thanks everyone for the help. > > I should have said that I want to do this generally, not as a one-off. > So I want a function to do it. Like this > > tp<-function(x, nr, nc) > { > matrix( c(x,rep(0, nr-length(x)+1)), nrow=nr, ncol=nc) > } > > tp(x=c(1,2), nr=5, nc=4) > > This one looks good -- the warning message is annoying though... > > > Bill > > ______________________________________________ > 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.