Re: [R] loop vs. apply(): strange behavior with data frame?

2009-10-22 Thread Roberto Perdisci
Thanks for the suggestion. I found some documentation on why accessing a data.gram using the matrix notation (e.g., [i,j]) is so expensive, which was the cause of the problem. regards, Roberto On Thu, Oct 22, 2009 at 12:05 AM, Jim Holtman jholt...@gmail.com wrote: try running Rprof on the

[R] loop vs. apply(): strange behavior with data frame?

2009-10-21 Thread Roberto Perdisci
Hi everybody, I noticed a strange behavior when using loops versus apply() on a data frame. The example below explicitly computes a distance matrix given a dataset. When the dataset is a matrix, everything works fine. But when the dataset is a data.frame, the dist.for function written using

Re: [R] loop vs. apply(): strange behavior with data frame?

2009-10-21 Thread Jim Holtman
try running Rprof on the two examples to see what the difference is. what you will probably see is a lot of the time on the dataframe is spent in accessing it like a matrix ('['). Rprof is very helpful to see where time is spent in your scripts. Sent from my iPhone On Oct 21, 2009, at