indexing according to frequency

Posted by Bfu38 on Stack Overflow See other posts from Stack Overflow or by Bfu38
Published on 2012-12-03T10:41:16Z Indexed on 2012/12/03 11:12 UTC
Read the original article Hit count: 96

Filed under:

sorry to bother you. I have a data.frame like this:

24.8     
23.2     
22.8        
22.5     
22.5      
22.4     
22.4      
22.4      
22.3     
22.2     
22.2      
22.2      
22      
21.9      
21.9     
21.8    

I would like to add an index according to the frequency, to have the following output:

24.8      1      
23.2      1      
22.8      1      
22.5      2      
22.5      2     
22.4      3       
22.4      3        
22.4      3        
22.3      1     
22.2      3          
22.2      3         
22.2      3        
22        1                
21.9      2           
21.9      2         
21.8      1

How this can be done? in other words, since 28.8 occurs 1 time, it will have the index 1; since 22.5 occurs two times, it will have index 2 and so on.

© Stack Overflow or respective owner

Related posts about r