[R] listing all occurrences in a vector
Ben Bolker
bbolker at gmail.com
Wed Oct 19 14:04:40 CEST 2011
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)
More information about the R-help
mailing list