Skip to content
Prev 312506 / 398506 Next

repeating matrices in a list

Hi,
Try this:
lapply(1:3,function(x) g)

A.K.





----- Original Message -----
From: Anser Chen <anser.chen at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Friday, November 30, 2012 12:50 PM
Subject: [R] repeating matrices in a list

Suppose I have the following? square, non-negative matrices
I want to create a list where this matrix is repeated multiple times. if I
do this brute force (manually), using
works fine. Yields

[[1]]
? ?  [,1] [,2] [,3]
[1,] 0.00? 2.0? ? 4
[2,] 0.25? 0.0? ? 0
[3,] 0.00? 0.6? ? 0

[[2]]
? ?  [,1] [,2] [,3]
[1,] 0.00? 2.0? ? 4
[2,] 0.25? 0.0? ? 0
[3,] 0.00? 0.6? ? 0

[[3]]
? ?  [,1] [,2] [,3]
[1,] 0.00? 2.0? ? 4
[2,] 0.25? 0.0? ? 0
[3,] 0.00? 0.6? ? 0



But - for a variety of purposes, I need to 'automate' building said list. I
tried using rep
but this yields

[1] 0.00 0.00 0.00 0.25 0.25 0.25 0.00 0.00 0.00 2.00 2.00 2.00 0.00 0.00
0.00
[16] 0.60 0.60 0.60 4.00 4.00 4.00 0.00 0.00 0.00 0.00 0.00 0.00

Any suggestions/pointers to the obvious?

Thanks in advance...

??? [[alternative HTML version deleted]]

______________________________________________
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.