s-news
[Top] [All Lists]

Speeding up a for loop

To: s-news@wubios.wustl.edu
Subject: Speeding up a for loop
From: gerald.jean@dgag.ca
Date: Wed, 24 Nov 2004 09:07:21 -0500
Hello S-users,

I am running the following loop at the top level --- not in a function ---
and it takes for ever!  It is running since 16h00 yesterday, hence over 17
hours so far.  It is not using too much memory though.  The data.frame it
is looping over is small, 284 observations, while the data.frame where the
assignements take place is huge, over 2M records.  Since I have two more
data.frames, even bigger, where I have to run the same loop I am wondering
if there is a way to speed up this loop or another way to get the task
done?

> for (i in 1:nrow(StatCanCNP)) {
+   QcProf.Ass.b2[QcProf.Ass.b2[, 'newprof'] == StatCanCNP[i, 'CodeProf'],
+                 c('Educ', 'Indus')] <- StatCanCNP[i, c('Education',
'CdIndus')]
+ }

The variables "Educ" and "Indus" in the large data.frame have been created
beforehand.

Here are the specs of my installation.

S-PLUS : Copyright (c) 1988, 2004 Insightful Corp.
S : Copyright Lucent Technologies, Inc.
Version 6.2.1  for Sun SPARC, SunOS 5.8, 64-bit : 2004

Thanks for any clues,

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>