[R] why is nrow() so slow?

Duncan Murdoch murdoch at stats.uwo.ca
Tue Sep 15 22:40:47 CEST 2009


On 9/15/2009 4:24 PM, ivo welch wrote:
> hi david---no, this time I actually know what I was asking ( ;-) ).   I do
> need speed computed on many data sets, each of which is created by a "by"
> statement.  so, no iterative programming on my side.
> 
> thanks, hadley for the pointer to .row_names_info() in lieu of dim() or
> nrows().  I don't seem to understand the second (type) argument, despite
> reading the docs, but all of them are giving the same answer in my data
> frames.  so, I guess I will stick to "2" for the time being.
> 

One note:  if you're worried about speed, it almost always makes sense 
to use matrices rather than dataframes.  If you've got mixed types this 
is tedious and error-prone (each type needs to be in a separate matrix), 
but if your data is all numeric, it's very simple, and will make things 
a lot faster.

Duncan Murdoch




More information about the R-help mailing list