[Rd] extracting rows from a data frame by looping over the row names: performance issues
Herve Pages
hpages at fhcrc.org
Fri Mar 2 20:03:07 CET 2007
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.
More information about the R-devel
mailing list