Skip to content

listing all occurrences in a vector

3 messages · Jonas Fransson, Paul Hiemstra, Ben Bolker

#
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
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?

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?
#
On 10/19/2011 09:00 AM, Jonas Fransson wrote:
Hi,

Use the rep function:

with(a, rep(DEPTH, times = NUMBER))

cheers,
Paul

  
    
#
Jonas Fransson <jf <at> iva.dk> writes:
5 (NUMBER=1 in all cases).
with(a,rep(DEPTH,NUMBER))

(in case someone else hasn't already answered)