Skip to content
Back to formatted view

Raw Message

Message-ID: <B25D197D366263478F81BF0052776F67064192@STPvMailbox01.srlglobal.local>
Date: 2011-10-05T16:15:27Z
From: Samuel Le
Subject: Populate a matrix
In-Reply-To: <A0C20390AF37844A9E2C783C9C268D8C496566EEB4@CCD1XM1101.ccd1.root4.net>

mat <- matrix(ncol = length(x), nrow = length(y))
for(i in 1:length(x)) { mat[,i] = y}

HTH,
Samuel

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of fernando.cabrera at nordea.com
Sent: 05 October 2011 17:11
To: r-help at r-project.org
Subject: [R] Populate a matrix

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

______________________________________________
R-help at r-project.org 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.


__________ Information from ESET NOD32 Antivirus, version of virus signature database 6275 (20110707) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



__________ Information from ESET NOD32 Antivirus, version of virus signature database 6275 (20110707) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com