v3 <- numeric()
v3[v1] <- table(v2)[v1]


Jim
__________________________________________________________
James Holtman        "What is the problem you are trying to solve?"
Executive Technical Consultant  --  Convergys Labs
[EMAIL PROTECTED]
+1 (513) 723-2929


                                                                                
                                                           
                      Federico Calboli                                          
                                                           
                      <[EMAIL PROTECTED]        To:       r-help 
<[email protected]>                                             
                      c.uk>                        cc:                          
                                                           
                      Sent by:                     Subject:  [R] vectorisation 
suggestion                                                  
                      [EMAIL PROTECTED]                                         
                                                       
                      ath.ethz.ch                                               
                                                           
                                                                                
                                                           
                                                                                
                                                           
                      06/20/2005 16:15                                          
                                                           
                                                                                
                                                           




Hi All,

I am counting the number of occurrences of the terms listed in one
vector in another vector.

My code runs:

for( i in 1:length(vector3)){
   vector3[i]  = sum(1*is.element(vector2,  vector1[i]))
}

where

vector1 = vector containing the terms whose occurrences I want to count
vector2 = made up of a number of repetitions of all the elements of
vector1
vector3 = a vector of NAs that is meant to get the result of the
counting

My problem is that vector1 is about 60000 terms, and vector2 is
620000... can anyone suggest a faster code than the one I wrote?

Cheers,

Federico Calboli


--
Federico C. F. Calboli
Department of Epidemiology and Public Health
Imperial College, St. Mary's Campus
Norfolk Place, London W2 1PG

Tel +44 (0)20 75941602   Fax +44 (0)20 75943193

f.calboli [.a.t] imperial.ac.uk
f.calboli [.a.t] gmail.com

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to