TrajsMergeStats | R Documentation |
Builds a data frame by combining rows of statistical values for multiple trajectories. The statistics for each trajectory are defined by the caller in a user defined function - see the example for one way to achieve this.
TrajsMergeStats(
trjs,
statsFn,
progressBar = c("none", "text", "win", "tk"),
check.names = TRUE,
...
)
trjs |
List of trajectories to be characterised. |
statsFn |
Function to calculate statistics of interest for a single trajectory. |
progressBar |
Displays an optional progressbar, which may be helpful if
processing is very slow. The progressbar is displayed by printing to the
console, by using |
check.names |
Passed to |
... |
Additional arguments passed to |
Any NULL valued statistics are converted to NAs.
## 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)
# 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)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.