[R] create one bigger matrix with one smaller matrix
David Winsemius
dwinsemius at comcast.net
Thu Dec 31 22:05:40 CET 2015
> On Dec 31, 2015, at 12:28 PM, Kathryn Lord <kathryn.lord2000 at gmail.com> wrote:
>
> Dear R users,
>
> Suppose that I have a matrix A
>
> A <- matrix(c(1,2,3,4),2,2)
>> A
> [,1] [,2]
> [1,] 1 3
> [2,] 2 4
>
> 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,] 1 3 1 3 1 3 1 3 1 3 1 3
> 1 3
> [2,] 2 4 2 4 2 4 2 4 2 4 2 4
> 2 4
> [3,] 1 3 1 3 1 3 1 3 1 3 1 3
> 1 3
> [4,] 2 4 2 4 2 4 2 4 2 4 2 4
> 2 4
> [5,] 1 3 1 3 1 3 1 3 1 3 1 3
> 1 3
> [6,] 2 4 2 4 2 4 2 4 2 4 2 4
> 2 4
> [7,] 1 3 1 3 1 3 1 3 1 3 1 3
> 1 3
> [8,] 2 4 2 4 2 4 2 4 2 4 2 4
> 2 4
> [9,] 1 3 1 3 1 3 1 3 1 3 1 3
> 1 3
> [10,] 2 4 2 4 2 4 2 4 2 4 2 4
> 2 4
> [11,] 1 3 1 3 1 3 1 3 1 3 1 3
> 1 3
> [12,] 2 4 2 4 2 4 2 4 2 4 2 4
> 2 4
> [13,] 1 3 1 3 1 3 1 3 1 3 1 3
> 1 3
> [14,] 2 4 2 4 2 4 2 4 2 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,] 1 3 1 3 1 3 1 3 1 3
[2,] 2 4 2 4 2 4 2 4 2 4
[3,] 1 3 1 3 1 3 1 3 1 3
[4,] 2 4 2 4 2 4 2 4 2 4
[5,] 1 3 1 3 1 3 1 3 1 3
[6,] 2 4 2 4 2 4 2 4 2 4
[7,] 1 3 1 3 1 3 1 3 1 3
[8,] 2 4 2 4 2 4 2 4 2 4
[9,] 1 3 1 3 1 3 1 3 1 3
[10,] 2 4 2 4 2 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]]
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 at 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
More information about the R-help
mailing list