Re: [R] Speeding up simulation of mean nearest neighbor distances

2007-10-03 Thread hadley wickham
It looks like you can pass a vector of neighbourhoods to nndist. nndist(rpp, k=2:10) Although you get some warnings, the answers appear to be the same. all.equal(t(sapply(2:10, function(i) nndist(rpp, k=i))), nndist(rpp, k=2:10)) This might be quite a lot faster, depending on how much work is c

Re: [R] Speeding up simulation of mean nearest neighbor distances

2007-10-03 Thread jim holtman
If you take a look at what is happening with Rprof, you will see that most of the time (96.6%) is being taken in the 'nndist' function, so if you want to improve your algorithm, can you somehow reduce the number of time you call it, or find a different approach. So it is a function of the algorith

[R] Speeding up simulation of mean nearest neighbor distances

2007-10-03 Thread Dale Steele
I've written the function below to simulate the mean 1st through nth nearest neighbor distances for a random spatial pattern using the functions nndist() and runifpoint() from spatsat. It works, but runs relatively slowly - would appreciate suggestions on how to speed up this function. Thanks. -