This last solution is what I was looking for, I was trying to avoid loops. 
Thanks!

-----Original Message-----
From: [email protected] [mailto:[email protected]] On 
Behalf Of Rainer Schuermann
Sent: 5. oktober 2011 18:29
To: [email protected]
Subject: Re: [R] Populate a matrix

m <- matrix( rep( y, length( x ) ), length( y ), length( x ) )


On Wednesday 05 October 2011 18:11:18 [email protected] wrote:
> Hi guys
> 
> I have vectors x <- c(1,2,3,4) and y <- c(4,3,9) and would like to generate a 
> matrix which has 3 rows (length(y)) and 4 
columns (length(x)), and each row is the corresponding y element repeated 
length(x) times.
> 
> 4,4,4,4
> 3,3,3,3
> 9,9,9,9
> 
> Thanks.
> 
> Fernando Álvarez
> 
> ______________________________________________
> [email protected] 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.

______________________________________________
[email protected] 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.

______________________________________________
[email protected] 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