Skip to content
Back to formatted view

Raw Message

Message-ID: <loom.20111019T140350-33@post.gmane.org>
Date: 2011-10-19T12:04:40Z
From: Ben Bolker
Subject: 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)