From hpages at fhcrc.org  Fri Mar  2 20:03:07 2007
From: hpages at fhcrc.org (Herve Pages)
Date: Fri, 02 Mar 2007 11:03:07 -0800
Subject: [Rd] extracting rows from a data frame by looping over the row
 names: performance issues
In-Reply-To: <45E86F69.80507@fhcrc.org>
References: <45E86F69.80507@fhcrc.org>
Message-ID: <45E874EB.7010503@fhcrc.org>

Herve Pages wrote:
...
> But if, instead of the above, I do this:
> 
>   > for (i in nrow(dat)) { row <- sapply(dat, function(col) col[i]) }

Should have been:

  > for (i in 1:nrow(dat)) { row <- sapply(dat, function(col) col[i]) }

> 
> then it's 20 times faster!!
> 
>   > system.time(for (i in 1:100) { row <- sapply(dat, function(col) col[i]) })
>      user  system elapsed
>     0.576   0.096   0.673

...

Cheers,
H.



[Rd] extracting rows from a data frame by looping over the row names: performance issues
Herve Pages