listing all occurrences in a vector
Jonas Fransson <jf <at> iva.dk> writes:
I have a dataframe with two columns, where NUMBER is the number of occurrences of DEPTH:
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).
Is there any simple solution to the problem?
with(a,rep(DEPTH,NUMBER)) (in case someone else hasn't already answered)