Learn R Programming

trajr (version 1.0.0)

TrajsMergeStats: Merge trajectory characteristics

Description

Builds a data frame by combining rows of statistical values for multiple trajectories.

Usage

TrajsMergeStats(trjs, statsFn, ...)

Arguments

trjs

List of trajectories to be characterised.

statsFn

Function to calculate statistics of interest for a single trajectory.

...

Additional arguments passed to statsFn.

Examples

Run this code
# NOT RUN {
# 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)

  # Measures of straightness
  sinuosity <- TrajSinuosity(trj)
  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)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab