On Jul 4, 2009, at 11:59 AM, William Simpson 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...

> tp<-function(x, nr, nc)
+ {suppressWarnings(
+ matrix( c(x,rep(0, nr-length(x)+1)),  nrow=nr, ncol=nc) )
+ }
>
> tp(x=c(1,2), nr=5, nc=4)
     [,1] [,2] [,3] [,4]
[1,]    1    0    0    0
[2,]    2    1    0    0
[3,]    0    2    1    0
[4,]    0    0    2    1
[5,]    0    0    0    2

--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
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.

Reply via email to