[R] repeated vector in matrix

Robin Hankin r.hankin at noc.soton.ac.uk
Thu Jun 2 14:44:44 CEST 2005


On Jun 2, 2005, at 01:23 pm, Dimitris Rizopoulos wrote:

> try this:

> h <- rep(3:2, c(4, 3))
> ############
> n  <- 10
> matrix(rep(h, n),  nrow = n, byrow = TRUE)
>


Hi

outer() also works:


 > h <-rep(c(3,2),c(4,3))
 > outer(rep(1,8),h)
      [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]    3    3    3    3    2    2    2
[2,]    3    3    3    3    2    2    2
[3,]    3    3    3    3    2    2    2
[4,]    3    3    3    3    2    2    2
[5,]    3    3    3    3    2    2    2
[6,]    3    3    3    3    2    2    2
[7,]    3    3    3    3    2    2    2
[8,]    3    3    3    3    2    2    2
 >

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743




More information about the R-help mailing list