I am quite new to R and I am trying to compute the gross distance (or the sum of the Euclidean distance on all data points) from two variables in my matrix and net distance (Euclidean distance between the first and last point of my data. So just a background on my data. My data is normally a csv file comprising of 5 variables: tracks of cells (called A), time interval, X and Y position of each cell, V=velocity. There is around 90 tracks per data and each track should be treated independent of each other.
dput(head(t1))
structure(list(A = c(0L, 0L, 0L, 0L, 0L, 0L), T = 0:5, X = c(668L,
668L, 668L, 668L, 668L, 668L), Y = c(259L, 259L, 259L, 259L,
259L, 259L), V = c(NA, 0, 0, 0, 0, 0)), .Names = c("A", "T",
"X", "Y", "V"), row.names = c(NA, 6L), class = "data.frame")
I was not aware of the dist() function before, so I made my own function:
GD.data <- function (trackdata)
{A= trackdata(, 1); V=trackdata(, 5);
for (i in min(A):max(A))
while (A<=i) {GD(i) = (sum (V)*(1/25))
return (GD(i))}
This did not work. I used A as an identifier of the track and since gross distance could be also computed as: distance=velocity (t1-t0), I just did summation of all velocity times my time interval (since it is constantly 1/25 secs.
How do I use the dist() function with my A as identifier? I need this since the computation of each track should be separate. Thanks!
trackdata) and are trying to reference the columns using e.g.(,1). You need to use[which is the subsetting function - i.e.trackdata[,1]will get you the first column. HTH! - Simon O'Hanlondput(head(trackdata))into your question as a code block, then we can recreate a small sample of your data on our computers. - Simon O'Hanlon