Dear list,
I would like to calculate the distance between consecutive points in a data
frame. Of course the first point in the data frame does not have a point of
origin, and should get a value NA. I have tried two different loops, which
both result in error:
num - seq(0,10,1)
X -
Hi!
It may bee that the function dist can be of some use to you?
?diff
I have something like this in mind. (you do not need a loop.)
XY$DistXY - sqrt(diff(X)^2+diff(Y)^2)
Have fun trying.
Sincerely Eryk
*** REPLY SEPARATOR ***
On 5/31/2004 at 5:25 PM Sander Oom wrote:
Dear
Try using running from the gregmisc package with pad = TRUE:
require(gregmisc)
XY - data.frame(num = seq(0,10), X = seq(0,30,3), Y = seq(0, 40, 4) )
DistXY - function(idx) {
i - idx[2]
with(XY, sqrt( (X[i]-X[i-1])^2 + (Y[i]-Y[i-1])^2 ) )
}
XY$Dist - running( 1:nrow(XY), width=2, fun =
Hi Gabor,
Thanks for your suggestion. However when installing the package gregmisc, I
get the following error:
local({a - CRAN.packages()
+ install.packages(select.list(a[,1],,TRUE), .libPaths()[1], available=a)})
trying URL `http://cran.r-project.org/bin/windows/contrib/1.9/PACKAGES'
Content
Sander Oom wrote:
Hi Gabor,
Thanks for your suggestion. However when installing the package
gregmisc, I get the following error:
local({a - CRAN.packages()
+ install.packages(select.list(a[,1],,TRUE), .libPaths()[1], available=a)})
trying URL