Re: [R] create one bigger matrix with one smaller matrix
A <- matrix(c(1,2,3,4),2,2) B <- matrix(A, nrow=14, ncol=14) > B [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [1,]131313131 3 1 3 1 3 [2,]242424242 4 2 4 2 4 [3,]313131313 1 3 1 3 1 [4,]424242424 2 4 2 4 2 [5,]131313131 3 1 3 1 3 [6,]242424242 4 2 4 2 4 [7,]313131313 1 3 1 3 1 [8,]424242424 2 4 2 4 2 [9,]131313131 3 1 3 1 3 [10,]242424242 4 2 4 2 4 [11,]313131313 1 3 1 3 1 [12,]424242424 2 4 2 4 2 [13,]131313131 3 1 3 1 3 [14,]242424242 4 2 4 2 4 > Happy New Year! -- GG [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] create one bigger matrix with one smaller matrix
> On Dec 31, 2015, at 12:28 PM, Kathryn Lordwrote: > > Dear R users, > > Suppose that I have a matrix A > > A <- matrix(c(1,2,3,4),2,2) >> A > [,1] [,2] > [1,]13 > [2,]24 > > With this matrix A, I'd like to create bigger one, for example, > > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] > [,14] > [1,]131313131 3 1 3 > 1 3 > [2,]242424242 4 2 4 > 2 4 > [3,]131313131 3 1 3 > 1 3 > [4,]242424242 4 2 4 > 2 4 > [5,]131313131 3 1 3 > 1 3 > [6,]242424242 4 2 4 > 2 4 > [7,]131313131 3 1 3 > 1 3 > [8,]242424242 4 2 4 > 2 4 > [9,]131313131 3 1 3 > 1 3 > [10,]242424242 4 2 4 > 2 4 > [11,]131313131 3 1 3 > 1 3 > [12,]242424242 4 2 4 > 2 4 > [13,]131313131 3 1 3 > 1 3 > [14,]242424242 4 2 4 > 2 4 > > str( do.call('rbind', rep(list( do.call('cbind' , rep(list(A), 20) ) ), 20) ) ) #result num [1:40, 1:40] 1 2 1 2 1 2 1 2 1 2 ... The "upper left" corner: do.call('rbind', rep(list( do.call('cbind' , rep(list(A), 20) ) ), 20) )[1:10, 1:10] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,]131313131 3 [2,]242424242 4 [3,]131313131 3 [4,]242424242 4 [5,]131313131 3 [6,]242424242 4 [7,]131313131 3 [8,]242424242 4 [9,]131313131 3 [10,]242424242 4 > In fact, I want much bigger one. I wonder if there is an elegant way to do > this? > > Any suggestions? Thank you! > > Best wishes and Happy new year > > Kathie > > [[alternative HTML version deleted]] Your use of HTML for email is not appropriate for this list. It messed up your example although the intent was not that difficult to discrn. -- David. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] create one bigger matrix with one smaller matrix
Well, all of the solutions proposed are a bit tricky in that the matrix must be "constructed" by hand. They are also reinventing wheels. What I think you really want is the kronecker product, which is the matrix operation that does exactly what you want. e.g. A <- matrix(1:4, nr=2) to create a new matrix with e.g. 2 x 6 "positions" in each of which is A, simply do kronecker (matrix(1, nr = 2, nc=6), A) or if you want to use the operator form: matrix(1,nr=2, nc=6) %x% A See ?kronecker Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Dec 31, 2015 at 12:28 PM, Kathryn Lordwrote: > Dear R users, > > Suppose that I have a matrix A > > A <- matrix(c(1,2,3,4),2,2) >> A > [,1] [,2] > [1,]13 > [2,]24 > > With this matrix A, I'd like to create bigger one, for example, > > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] > [,14] > [1,]131313131 3 1 3 > 1 3 > [2,]242424242 4 2 4 > 2 4 > [3,]131313131 3 1 3 > 1 3 > [4,]242424242 4 2 4 > 2 4 > [5,]131313131 3 1 3 > 1 3 > [6,]242424242 4 2 4 > 2 4 > [7,]131313131 3 1 3 > 1 3 > [8,]242424242 4 2 4 > 2 4 > [9,]131313131 3 1 3 > 1 3 > [10,]242424242 4 2 4 > 2 4 > [11,]131313131 3 1 3 > 1 3 > [12,]242424242 4 2 4 > 2 4 > [13,]131313131 3 1 3 > 1 3 > [14,]242424242 4 2 4 > 2 4 > > > In fact, I want much bigger one. I wonder if there is an elegant way to do > this? > > Any suggestions? Thank you! > > Best wishes and Happy new year > > Kathie > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
[R] create one bigger matrix with one smaller matrix
Dear R users, Suppose that I have a matrix A A <- matrix(c(1,2,3,4),2,2) > A [,1] [,2] [1,]13 [2,]24 With this matrix A, I'd like to create bigger one, for example, [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [1,]131313131 3 1 3 1 3 [2,]242424242 4 2 4 2 4 [3,]131313131 3 1 3 1 3 [4,]242424242 4 2 4 2 4 [5,]131313131 3 1 3 1 3 [6,]242424242 4 2 4 2 4 [7,]131313131 3 1 3 1 3 [8,]242424242 4 2 4 2 4 [9,]131313131 3 1 3 1 3 [10,]242424242 4 2 4 2 4 [11,]131313131 3 1 3 1 3 [12,]242424242 4 2 4 2 4 [13,]131313131 3 1 3 1 3 [14,]242424242 4 2 4 2 4 In fact, I want much bigger one. I wonder if there is an elegant way to do this? Any suggestions? Thank you! Best wishes and Happy new year Kathie [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] create one bigger matrix with one smaller matrix
Something like: A <- matrix(c(1,2,3,4),2,2) A B <- matrix(rep(A, 4), nrow=2) B C <- do.call(rbind, lapply(1:8, function(x) B)) C On Thu, Dec 31, 2015 at 12:28 PM, Kathryn Lordwrote: > Dear R users, > > Suppose that I have a matrix A > > A <- matrix(c(1,2,3,4),2,2) >> A > [,1] [,2] > [1,]13 > [2,]24 > > With this matrix A, I'd like to create bigger one, for example, > > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] > [,14] > [1,]131313131 3 1 3 > 1 3 > [2,]242424242 4 2 4 > 2 4 > [3,]131313131 3 1 3 > 1 3 > [4,]242424242 4 2 4 > 2 4 > [5,]131313131 3 1 3 > 1 3 > [6,]242424242 4 2 4 > 2 4 > [7,]131313131 3 1 3 > 1 3 > [8,]242424242 4 2 4 > 2 4 > [9,]131313131 3 1 3 > 1 3 > [10,]242424242 4 2 4 > 2 4 > [11,]131313131 3 1 3 > 1 3 > [12,]242424242 4 2 4 > 2 4 > [13,]131313131 3 1 3 > 1 3 > [14,]242424242 4 2 4 > 2 4 > > > In fact, I want much bigger one. I wonder if there is an elegant way to do > this? > > Any suggestions? Thank you! > > Best wishes and Happy new year > > Kathie > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.