[R] replicate matrix blocks different numbers of times into new matrix
Ralph S.
ruffel1 at hotmail.com
Sat Jul 19 20:30:50 CEST 2008
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 - first column entries are both data and the two factors
x<-matrix(c(1,2,3,4),2,2)
> x
[,1] [,2]
[1,] 1 3
[2,] 2 4
# the number of repetitions of the first and second factor
n<-c(1,3)
This is what I want as output:
[,1] [,2]
[1,] 1 3
[2,] 2 4
[3,] 2 4
[4,] 2 4
Any ideas how to get there? I have tried using tapply with combination of rep, but this does not work (I need 1 and then 3 replications).
Any help would be great!
-Ralph
_________________________________________________________________
With Windows Live for mobile, your contacts travel with you.
072008
More information about the R-help
mailing list