if (FALSE) {
# Define a function which calculates some statistics
# of interest for a single trajectory
characteriseTrajectory <- function(trj) {
  # Measures of speed
  derivs <- TrajDerivatives(trj)
  mean_speed <- mean(derivs$speed)
  sd_speed <- sd(derivs$speed)
  # Resample to constant step length.
  # Step length must be appropriate for the trajectory
  resampled <- TrajRediscretize(trj, 2)
  # Measures of straightness
  sinuosity <- TrajSinuosity2(resampled)
  Emax <- TrajEmax(resampled)
  # Periodicity
  resampled <- TrajRediscretize(trj, .001)
  corr <- TrajDirectionAutocorrelations(resampled, round(nrow(resampled) / 4))
  first_min <- TrajDAFindFirstMinimum(corr)
  # Return a list with all of the statistics for this trajectory
  list(mean_speed = mean_speed,
       sd_speed = sd_speed,
       sinuosity = sinuosity,
       Emax = Emax,
       first_min_deltaS = first_min[1],
       first_min_C = first_min[2])
}
trjs <- TrajsBuild(filenames)
stats <- TrajsMergeStats(trjs, characteriseTrajectory)
}
Run the code above in your browser using DataLab