listing all occurrences in a vector
On 10/19/2011 09:00 AM, Jonas Fransson wrote:
Dear all, I have a dataframe with two columns, where NUMBER is the number of occurrences of DEPTH: DEPTH NUMBER 1 2 1 2 3 2 3 2 3 4 5 1
a<-data.frame(c(2,3,2,5),c(1,2,3,1))
colnames(a)=c("DEPTH","NUMBER")
I want a column or a vector where all the DEPTHs are listed: 2, 3, 3, 2, 2, 2, 5 (NUMBER=1 in all cases).
Hi, Use the rep function: with(a, rep(DEPTH, times = NUMBER)) cheers, Paul
Is there any simple solution to the problem? Thanks, Jonas Jonas Fransson Ph.D.stud. IVA / Det Informationsvidenskabelige Akademi Royal School of Library and Information Science Birketinget 6 DK-2300 Copenhagen S T +45 32 58 60 66 D +45 32 34 15 10 www.iva.dk/jf
______________________________________________ R-help at 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.
Paul Hiemstra, Ph.D. Global Climate Division Royal Netherlands Meteorological Institute (KNMI) Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39 P.O. Box 201 | 3730 AE | De Bilt tel: +31 30 2206 494 http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770