[R] rbind question

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Tue Jul 8 16:11:30 CEST 2003



David Andel wrote:
> Hi
> 
> I am trying to replicate a vector in n rows for comparison purposes with 
> another matrix.
> 
> foo <- c(1,2,3)
> bar <- rbind(foo,foo) # does the trick for 2 rows
> bar <- rbind(rep(foo,2)) # does something else
> 
> How do I generate a matrix with all rows=foo without writing 'foo' n times as 
> arg?
> 

How about:

foo <- 1:3
n <- 10 # number of rows
matrix(rep(foo, n), nr = n, byrow = TRUE)

Regards,
Sundar




More information about the R-help mailing list