Try this: unique(x)[rep(1:nrow(unique(x)), m),]
On Wed, Dec 30, 2009 at 2:35 PM, <farida...@gmail.com> wrote: > Dear All, > > I have a matrix like X and need to create a new matrix based on the vector > m which gives the number of replicates for each unique row. The resulting > matrix should look like y. > >> x > x1 x2 > [1,] 2 0.5 > [2,] 2 0.5 > [3,] 2 0.5 > [4,] 6 1.0 > [5,] 6 1.0 > [6,] 6 1.0 > [7,] 1 1.5 > [8,] 1 1.5 > [9,] 1 1.5 > [10,] 4 2.0 > [11,] 4 2.0 > [12,] 3 2.5 > [13,] 3 2.5 > [14,] 3 2.5 > > > m<-c(1,1,3,1,2) > >> y > y1 y2 > [1,] 2 0.5 > [2,] 6 1.0 > [3,] 1 1.5 > [4,] 1 1.5 > [5,] 1 1.5 > [6,] 4 2.0 > [7,] 3 2.5 > [8,] 3 2.5 > > can anyone suggest the best way to do this? > > Many thanks in advance, > > > Farida > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O ______________________________________________ R-help@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.