try this: > x <- data.frame(Name = c("a", "b", "c", "d"), Group = c("VR", "MR", "VR", + "LR"), Number = c(2, 3, 4, 2)) > x Name Group Number 1 a VR 2 2 b MR 3 3 c VR 4 4 d LR 2 > x.new <- x[rep(seq(nrow(x)), times=x$Number),] > x.new Name Group Number 1 a VR 2 1.1 a VR 2 2 b MR 3 2.1 b MR 3 2.2 b MR 3 3 c VR 4 3.1 c VR 4 3.2 c VR 4 3.3 c VR 4 4 d LR 2 4.1 d LR 2
On Tue, Mar 9, 2010 at 8:06 PM, Steven Kang <stochastick...@gmail.com>wrote: > Hi all, > > I wish to generate additional records according to one of the field values > in a data frame. > > For example, unique record from the input data is required to be generated > number of times as specified in the 'Number' field in the following code. > > > x <- data.frame(Name = c("a", "b", "c", "d"), Group = c("VR", "MR", "VR", > "LR"), Number = c(2, 3, 4, 2)) > > x > Name Group Number > 1 a VR 2 > 2 b MR 3 > 3 c VR 4 > 4 d LR 2 > The desired output is: > > Name Group Number > 1 a VR 2 > 2 a VR 2 > 3 b MR 3 > 4 b MR 3 > 5 b MR 3 > 6 c VR 4 > 7 c VR 4 > 8 c VR 4 > 9 c VR 4 > 10 d LR 2 > 11 d LR 2 > > It would be greatly appreciated if you could provide resolution in this > matter. > > Thanks. > > > > > -- > Steven > > [[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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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.