s-news
[Top] [All Lists]

Summary: Speeding up a for loop

To: s-news@wubios.wustl.edu
Subject: Summary: Speeding up a for loop
From: gerald.jean@dgag.ca
Date: Wed, 24 Nov 2004 10:39:25 -0500
Thanks to all who responded:  Arjun Bhandari, Rich Herberger and David
Lorenz,

Rich suggested an approach using "match", it works nicely if there is a
unique match from the large data.frame, but in this case there is multiple
matches and "match" will only return the first match.

David Lorenz suggested to use "merge", which I did after testing on a small
example.  Very fast and efficient:

> resources(tmp.b2 <- merge(x = QcProf.Ass.b2,
+                           y = StatCanCNP[, c('CodeProf', 'SC.CNP',
'Education',
+                             'CdIndus')],
+                           by.x = 'newprof', by.y = 'CodeProf', all.x =
T))
 User time    =  0 h.  0 min.  55.27 s.
 System time  =  0 h.  0 min.   0.91 s.
 CPU time     =  0 h.  0 min.  56.18 s.
 Elapsed time =  0 h.  0 min.  56.42 s.
 Child        =  0 h.  0 min.   0.00 s.
 % CPU        =  99.57

 Memory usage:
      Cache   = 0 Bytes
      Working = 755.029467M Bytes

Thanks again for the help,

Gérald Jean
Analyste-conseil (statistiques), Actuariat
télephone            : (418) 835-4900 poste (7639)
télecopieur          : (418) 835-6657
courrier électronique: gerald.jean@dgag.ca

"In God we trust all others must bring data"  W. Edwards Deming



<Prev in Thread] Current Thread [Next in Thread>
  • Summary: Speeding up a for loop, gerald . jean <=