Ophelia and Others, A more general solution is:
## define a function (that is part of the mefa package) `rep.data.frame` <- function(x, ...) as.data.frame(lapply(x, rep, ...)) ## example from ?mefa:::rep.data.frame x <- data.frame(sample = LETTERS[c(1,1,2,2,3)], species = letters[c(5,5,5,6,7)], count = c(1,2,10,3,4), segment = letters[c(8,9,8,9,8)]) x rep(x[,c(1,2,4)], times = x[,3]) rep(x[,c(1,2,4)], each = 2) Cheers, Peter On Mon, Dec 6, 2010 at 5:07 AM, zhangjl <zhan...@ibcas.ac.cn> wrote: > Dear Ophelia, > If your dataframe is already in memory, simply write > as.character(rep(dat[,1],dat[,2]) , > to finish the task. > > Aegiinte 3 > Agonperu 3 > Aiouimpr 2 > Albiniop 2 > Albisubd 1 > .................. > else, you may try the following code, if your data is saved on the disk. > > dat <- read.csv("dat2.csv") > writeLines(as.character(rep(dat[,1],dat[,2])), "Lines.csv") > > Hope these commands will help. > > best, > Jinlong > > > 2010-12-06 > > > > Jinlong Zhang > Ph.D.Candidate > State Key Laboratory for Vegetation and Environmental Change, > Institute of Botany, The Chinese Academy of Sciences > Nanxincun 20,Xiangshan, Beijing 100093 > E-mails: > zhan...@ibcas.ac.cn > jinlongzhan...@gmail.com > > > > > 发件人: Ophelia Wang > 发送时间: 2010-12-06 16:51:21 > 收件人: r-sig-ecology > 抄送: > 主题: [R-sig-eco] Converting species counts into species list > > Hello, > I have a list of species and abundance that looks like this: > Aegiinte 3 > Agonperu 3 > Aiouimpr 2 > Albiniop 2 > Albisubd 1 > .................. > And I need to convert these two columns into a column in which each > cell represents an individual of a articular species: > Aegiinte > Aegiinte > Aegiinte > Agonperu > Agonperu > Agonperu > Aiouimpr > Aiouimpr > Albiniop > Albiniop > Albisubd > ......... > Can someone help me to develop a script to do the conversion? > Thanks a lot! > Ophelia > _______________________________________________ > R-sig-ecology mailing list > R-sig-ecology@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology > > [[alternative HTML version deleted]] > > > _______________________________________________ > R-sig-ecology mailing list > R-sig-ecology@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology > > _______________________________________________ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology