[R] matrix problem

David Winsemius dwinsemius at comcast.net
Sat Jul 4 18:05:43 CEST 2009


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




More information about the R-help mailing list