Converting species counts into species list
Dear all, Thank you thank you thank you! Your scripts are really helpful! Ophelia
On Mon, Dec 6, 2010 at 7:30 AM, Peter Solymos <solymos at ualberta.ca> wrote:
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 <zhangjl at 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:
zhangjl at ibcas.ac.cn
jinlongzhang01 at 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 at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology [[alternative HTML version deleted]] _______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Yung-Ho (Ophelia) Wang PhD Candidate Department of Geography and the Environment University of Texas at Austin