Re: [R] replicate matrix

2010-02-22 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of wendy > Sent: Saturday, February 20, 2010 6:58 PM > To: r-help@r-project.org > Subject: [R] replicate matrix > > > Hi all, > > I have a ma

Re: [R] replicate matrix

2010-02-20 Thread Linlin Yan
You can just rep() it, and c() with extra data, and then matrix() it again: > m <- matrix(c(1,4,3,6),2) > matrix(c(rep(m, 3), c(2, 5)), nrow(m)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]1313132 [2,]4646465 On Sun, Feb 21, 2010 at 10:58 AM,

Re: [R] replicate matrix

2010-02-20 Thread Dimitris Rizopoulos
try this: mat <- matrix(c(1,4,3,6), 2, 2) cbind( do.call(cbind, rep(list(mat), 3)), c(2, 5) ) I hope it helps. Best, Dimitris wendy wrote: Hi all, I have a matrix, for example [,1] [,2] [1,] 13 [2,] 46 I want to replicate the matrix twice and add an extra column at

Re: [R] replicate matrix

2010-02-20 Thread amarov
You can try something like: mtx <- matrix(1:4, ncol = 2) mtx.rep <- t(apply(mtx, 1, rep, r)) mtx.rep <- cbind(mrx.rep, new.column) where r is your desired number of replications . Hope it helps, Boyko Joshua Wiley-2 wrote: > > Hello Wendy, > > The simplest solution that comes to mind is t

Re: [R] replicate matrix

2010-02-20 Thread Joshua Wiley
Hello Wendy, The simplest solution that comes to mind is to just use cbind. For instance: > x <- matrix(1:4, nrow=2) > x [,1] [,2] [1,]13 [2,]24 > cbind(x,x,x,c(2,5)) # repeat x here as many times as needed [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]1313

[R] replicate matrix

2010-02-20 Thread wendy
Hi all, I have a matrix, for example [,1] [,2] [1,] 13 [2,] 46 I want to replicate the matrix twice and add an extra column at the end, which is [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 13 13 132 [2,] 46 46 465 I found 'rep' o

Re: [R] replicate matrix blocks different numbers of times into new matrix

2008-07-19 Thread Ralph S.
yes, this works, thank yo. very smart solution! -R > Date: Sat, 19 Jul 2008 19:55:58 -0400 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > Subject: Re: [R] replicate matrix blocks different numbers of times into new > matrix

Re: [R] replicate matrix blocks different numbers of times into new matrix

2008-07-19 Thread jim holtman
olve my > problem? > > Best, > > Ralph > > >> Date: Sat, 19 Jul 2008 21:39:25 +0200 >> From: [EMAIL PROTECTED] >> To: [EMAIL PROTECTED] >> CC: r-help@r-project.org >> Subject: Re: [R] replicate matrix blocks di

Re: [R] replicate matrix blocks different numbers of times into new matrix

2008-07-19 Thread Ralph S.
9:25 +0200 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > CC: r-help@r-project.org > Subject: Re: [R] replicate matrix blocks different numbers of times into new > matrix > > Ralph S. wrote: >> Hi, >> >> I am trying to replicate blocks of a matrix (defined

Re: [R] replicate matrix blocks different numbers of times into new matrix

2008-07-19 Thread Peter Dalgaard
Ralph S. wrote: Hi, I am trying to replicate blocks of a matrix (defined by factors) into another matrix, but an unequal, consecutive number of times for each factor. I need to find an elegant and fast way to do this, so loops will not work. An example of what I am trying to do is the follow

[R] replicate matrix blocks different numbers of times into new matrix

2008-07-19 Thread Ralph S.
Hi, I am trying to replicate blocks of a matrix (defined by factors) into another matrix, but an unequal, consecutive number of times for each factor. I need to find an elegant and fast way to do this, so loops will not work. An example of what I am trying to do is the following: # the data