Re: [R] repeated vector in matrix

From: Robin Hankin <r.hankin_at_noc.soton.ac.uk>
Date: Thu 02 Jun 2005 - 22:44:44 EST

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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu Jun 02 22:47:22 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:21 EST